mysql

Adding MySQL alias fields together

Consider a query similar to: SELECT sum(EXPR) as total, sum(EXPR) as total2, sum(total+total2) as grandtotal FROM tablename This comes up and says unknown column total in field list. Is there anyway to reference the alias fields in a calculation without retyping the sum expression because sum(EXPR) on each side is...

php and database question

I've been working on a website on my own xampp server on my computer with my own database and everything and so far it's been pretty smooth, surprisingly. Now I want to upload it to a host, and I found a free web host and I was able to upload the site through dreamweaver/ftp. I exported my DB into an SQL query and than ran that query o...

In mysql has the same effect in speed terms using a UNIQUE key than a NORMAL key?

For example, I'm doing the next action: SELECT COUNT(id) FROM users WHERE unique_name = 'Wiliam' // if Wiliam don't exists then... INSERT INTO users SET unique_name = 'Wiliam' The question is, I'm doing the SELECT COUNT(id) check every time I insert a new user, despite of using an unique key or not, so... if "unique_name" h...

Using Regex in MySQL WHERE clauses under specific conditions

Essentially, I'm working on a PHP-Based CMS and I'm looking to add an additional layer of security for the plugin infrastructure. Currently authors must secure their SQL clauses using traditional means, which is no problem. The CMS accepts queries in seperate parts, and the WHERE clause is one part. As an added layer of security, what I...

How to link a large number of items at one time in mysql and php?

For example: There are 10,000 items in a list and the user needs to be able to select a portion of these based on whatever criteria, and then put them into a group. So as the user, I filter the list of these 10,000 items based on whatever, hit select all and then click "Group". I'm trying to come up with the most efficient method of l...

How to eliminate "duplicate" URL MySQL rows which may or may not start with www?

I've been using a Drupal module called FeedAPI De-Dupe to remove duplicate records from my site's (MySQL) database. The module does a great job, but I'm still left with some "duplicates" when the URLs sometimes contain "www" and sometimes don't. The code handling the duplicate detection is: case 0: //url-based $sql = "SELECT n.nid ...

How to handle MySQL shutdown in Matlab?

Greetings all- I'm writing a program that parses and cleans a lot of data from one database to another on Matlab, querying from MySQL. This would run continuously, as new data come into the first db every minute, are cleaned, and put to the clean db before the next data point comes in. I was wondering how, during this process, I could a...

Hashtag RegEx for SQL query

So I am trying to incorporate a hashtag search into posts on my application. I have come up with a few close Regular Expressions, but none seem to work. Let's say I have a string: #i keep #hashtags in my mom's attic. She says I am her number #1 son. Why I'm not num#ber #2: http://pics.com/pic#thepic I would want the RegEx to m...

Error in phpmyadmin though runs fine in php script

Ok so this one is strange and I'm thinking there must be a problem in my sql query but I don't see anything wrong with it. What is happening is that I have a script that I am running in a php script that retrieves all categories that a user has signed up for as well as how many other people have signed up for the same category. When I ru...

How to benchmark and optimize a really database-intensive Rails action?

There is an action in the admin section of a client's site, say Admin::Analytics (that I did not build but have to maintain) that compiles site usage analytics by performing a couple dozen, rather intensive database queries. This functionality has always been a bottleneck to application performance whenever the analytics report is being...

CakePHP - $hasAndBelongsToMany and $hasMany relationships between tables that reside on separate databases and have different querying languages?

I have quite the complex problem to tell you about Stackoverflow, you see I have three tables that I need to define associations between for an application. These tables are: engineers, tickets, and testcases. I need to have a $hasMany relationship between engineers and tickets, and a hasAndBelongsToMany relationship between testcases an...

MySQL Query "One to Many" question.

OK I am going to try to explain this the best I can and maybe someone will understand it. I have a CRM application I am building and have the following tables: contacts, email, phone, website and address. I have been trying to create a Query that gathers all the info into one result set. I have kind of found a way that works 99.9% but I ...

Storing byte array in MySQL Blob with VBA

Anybody have some VBA code that will store a byte array into a MySQL blob column? ...

MySQL INSERT INTO Statement

I need some help with an insert statement. I've got: my_table_a: School Latitude Longitude Old School 38.6... -90.990... New School 38.6... -90.990... Other School 38.6... -90.990... Main School 38.6... -90.990... my_table_b: School Latitude Longitude City School Old School Centra...

mySql sum a column and return only entries with and entry in last 10 minutes

heres a table, the time when the query runs i.e now is 2010-07-30 22:41:14 number | person | timestamp 45 mike 2008-02-15 15:31:14 56 mike 2008-02-15 15:30:56 67 mike 2008-02-17 13:31:14 34 mike 2010-07-30 22:31:14 56 bob 2009-07-30 22:37:14 67 bob 2009-07-30 22:37:14 22 ...

export mysql data to csv file

Hi, I am trying to do 2 output data from mysql to a csv file. My code is as follows: public void exportData(Connection conn,String filename) { Statement stmt; String query; try { stmt = conn.createStatement(); //For comma separated file query = "SELECT * into OUTFILE '/tmp/input.csv'...

Create a table from an old one selecting specific rows

how can I create a new table selecting specific rows of the old table ? The selected 3 rows have field1 = 243, 245 and 248 respectively. Also I need to select the rows with field1 > 0 from table3. thanks ...

Why index made this query slower?

Table has 1 500 000 records, 1 250 000 of them have field = 'z'. I need select random not 'z' field. $random = mt_rand(1, 250000); $query = "SELECT field FROM table WHERE field != 'z' LIMIT $random, 1"; It is working ok. Then I decided to optimize it and indexed field in table. Result was strange - it was slower ~3 times. I te...

Using SQL to find the total number of customers with over X orders

Hey all, I've been roasting my brain with my limited SQL knowledge while attempting to come up with a query to run a statistic on my orders database. Table ORDERS is laid out like this: CustomerID ProductID (etc) 1 10 1 10 1 11 2 10 4 9 Each purchase is recorded with t...

Compare 2 fields in 2 tables and extract data

How do i compare 2 fields in 2 tables, find a match and use it ? example: table1: data1(id_data1,name,address,phone,account) table2: data2(id_data2,name2) now in php: if (name2.table2 has a matching name in name.table1) { give me the address,phone,account } ...