SQL Query Works Only In Win32!
I use MySQL from my php page and from phpMyAdmin.
In Windows Server, following query works fine. In Linux Server instead it returns error.
The SQL Query is:
SELECT DISTINCT a.id, a.container, b.container FROM folder AS a JOIN folder AS b ON a.container=b.id
The PHP error is:
You have an error in your SQL syntax near 'ON a.container=b.id' at line 1
So, I ask: If in Windows this query work fine, where is the error in the Linux version?
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
- Query Only Works Once
- JOIN Query Works With 3.23 But Not 4.0.13
- Parentheses: Query Works With 4.1.7, But Not With 4.1.11
- JOIN Query Works With 3.23 But Not 4.0.13
- Query Works With One Record
- GROUP_CONCAT Problem In 5.0.24 (query Works In 5.0.18)
- Query Help. This Works, But I Don't Think It Is Good Practice
- SQL Query Works Fine With Phpmyadmin But Gives Me No Results And EOF With ASP
- Perl, DBI, MySQL And UTF-8 Under Win32.
- MySQL 4.1.14 On Win32 Just After Install
- Make Win32 Installer NOT Always-on-top ?
- MySQL Win32 Install
- MYSQL + Win32 = Difficulties
- Running MySQL Win32
- Troyan.Win32.Zapchast.d
- Secure Backup On Win32 Systems?
- Secure Backup On Win32 Systems?
- Mysql 4.1.16 Win32.msi Error Message
- Installing Mysql-noinstall-4.1.11-win32.zip On Windows XP
- Works
- Works In MYSQL 4.1 But Not In 5.0
- How Exactly The LIKE Keyword Works?
- UNION - Works In 4.0.16, Not In 4.1.8
- SSN Changes In Database But Still Works As Key?
- How Exactly The LIKE Keyword Works?
- How Decimal Works
- UPDATE Works In MS SQL
- MySQL Delete: Works In Php 5 But Not Php 4?
- SHOW DATABASES Works In 4.0.14
- SHOW DATABASES Works In 4.0.14
- Exporting MS Works For MySQL
- Mysql.exe Sort Of Works
- Suddenly A Script No Longer Works
- V. 4.1.7 + Php4 Works, + Php5 Problems
- Two Different Websites Connected To One Database But Only One Works...
- Delete Using Multiple Table: Works On 4.1.20, But Not On 4.0.16
- My MySQL Back-end Works Very Slow
- Can't Update Multiple Rows Via PHP, But Works In PhpMyAdmin
- Quering Works Except Need To Sort Results By Other Table...
- Mysql Mysql-4.1.10-win32 Problem
- Using "WHERE LIKE '%Word'" That *will* Use An Index... Works But Feels Stupid!
- Free Mysql GUI Mysql "client" For Win32
- Error With SQL Statement When Using MySQL 5.0.24 (Works Fine In MySQL 4.0)
- UNION, Individually Works Fine, But Not In Union
- User Problems... Only Root User "works".
- How Can I Make A Query Like Microsoft Access, And A Query From A Query
- How To Create Efficient MySQL Query From A Pseudo Query
- Simple Sql Question: Using A Query Result As A Query Variable
- Query Based On Results Of A Previous Query
Query Only Works Once
I'm using jsp with mysql and am querying the database for data. Everything works fine on the first try. If I click back on my browser and hit submit again on my form, I get no data. I've tried removing the close() commands but that doesn't seem to work.
JOIN Query Works With 3.23 But Not 4.0.13
I have a simple join query below which queries the name of schools with count of student numbers for each school from two tables School,Student. select sc.name, Sum(if(student.SNO is not null, 1, 0)) nmbr, from school sc left outer join student on sc.school_id = student.school_id group by sc.school_id this runs just 0.30 sec with Mysql3.23 but 30Sec with Mysql 4.0.13. i could not find a solution.But i suspect from NULL threatment.
Parentheses: Query Works With 4.1.7, But Not With 4.1.11
Since we updated to the newest MySQL version (Windows) some of our queries do not work any more. It's reproducable by this (dummy) query: SELECT B.ID from ((SELECT * from A) AS T1 INNER JOIN B a ON B.ID = T1.ID); This works with 4.1.7, but not with 4.1.11, unless the parentheses are removed: SELECT B.ID from (SELECT * from A) AS T1 INNER JOIN B a ON B.ID = T1.ID; Does anybody know why MySQL changed its behaviour that way? I know the parentheses in the first query are not necessary, but it would be quite difficult to search through all our queries for unnecessary parentheses.
Query Works With One Record
This query works great if there is one matching record in the Albums table. When there's more than one matching record it returns nothing. Code: SELECT Artists.Artist, Albums.Album_Name FROM Artists, Albums WHERE SOUNDEX('colname') = SOUNDEX(Artists.Artist) AND Albums.Artist_ID=Artists.Id
GROUP_CONCAT Problem In 5.0.24 (query Works In 5.0.18)
So on my production server they are running MySQL - 5.0.24-standard. Locally I'm only running 5.0.18 but didn't figure it would be much of a problem, until I noticed that my "results" from certain searches were different with the exact same data on each MySQL version. The query is this:
Query Help. This Works, But I Don't Think It Is Good Practice
comics: id date location comments: id comicid datetime header comment author Every comic can have multiple comments. Each comic will have a comment, but there is a period of time where the comic is posted but the first comment is not yet submitted. So for argument's sake we can't assume there is any comment at all for a given comic. I want the all the comic ids and dates before a certain date along with the most first comment entered relating to that comic. select comics.date , comics.id , comments.header from comics left outer join comments on comments.comicid = comics.id where (comics.date>=񟭇-03-01') group by comics.id I never defined WHICH header should be returned when many are grouped together. I just know that mysql will return the first one in this circumstance. I seem to recall reading somewhere that different databases handle this sort of thing differently, with some returning a null in that field? I keep trying to forumate a useful subquery but keep drawing blanks just as I think I have it figured out in my head. Like I forget how the string starts by the time I mentally formulate the end....
Perl, DBI, MySQL And UTF-8 Under Win32.
finally I succeeded in inserting Unicode (namely utf8) strings into a MySQL database, but what I still don't know is how to query the database to avoid getting ? instead of e.g. ?. (áéö works somehow, since they are among latin1 (iso-8859-1) characters). Code:
MySQL 4.1.14 On Win32 Just After Install
Here is what I get when I try running MySQLShow: C:Documents and Settingsmorla_jb>mysqlshow mysqlshow: Access denied for user 'ODBC'@'localhost' (using password: NO) Any idea?
Make Win32 Installer NOT Always-on-top ?
I noticed that the windows installer wizard window is always-on-top, which I find very annoying. Other install wizard don't behave like this. Is there a way to turn it off ? I used the file mysql-essential-5.1.12-beta-win32.msi on WinXPproSP2.
MySQL Win32 Install
I've downloaded MySQL community server, the one without the installer, and I've unzipped it into c:. The last time I tried, I downloaded the one with the installer, and well.. I'm entirely newbie so once I did the installation and configuration, the computer start progressively work strange until I had to install windows xp again from zero. I need to install and configure the MySQL database locally, I mean I don't want it to connect to internet. I'm trying to install a weblog server application in this computer but I don't need the weblog to connect to internet, just work into the computer. I don't know nothing about server configuration, databases and things related. Therefore I would like some help configuring MySQL to work locally so the computer OS wont be in danger.
MYSQL + Win32 = Difficulties
I've a newbie to MySQL. I've installed it on Windows and assigned a password to the root user. Now when I log in I do the following: C:mysqlin>mysql -u root -p Enter password: ***** But all I get is: ERROR 1045: Access denied for user: 'root@localhost' (Using password: YES) I can't seem to find an answer as to why i'm hitting this problem. Can someone please explain?
Running MySQL Win32
I'm an absolute beginner and would really like to read something in the manual to solve this problem, but the manual just take care of Unix and Linux users. Because we develop on NT we wanted to install MySQL with Apache and PHP3 on a NT workstation for faster testing beside our Linux station. But I have problem to start the program (mysql.exe). It just gives back an error: Error 2003: can't connect to MySQL server on localhost 10061 Network is running, I can ping localhost. I don't know what to do to get it running.
Troyan.Win32.Zapchast.d
my antivirus (kaspersky) say: c:mysqldatahvocd.dll is a Troyan: Troyan.Win32.Zapchast.d i have winXP home and mysql Ver 12.22 Distrib 4.0.18, for Win95/Win98 (i32) can this file be infected by this troyan? can someone send me the original file hvocd.dll?
Secure Backup On Win32 Systems?
mostly for unix platforms. On win32, what is the best way to run a secure mysqldump so that my password doesn't have to live in a script somewhere? I'm using perl scripts to kick off my backup commands.
Secure Backup On Win32 Systems?
i know items have been posted before, mostly for unix platforms. On win32, what is the best way to run a secure mysqldump so that my password doesn't have to live in a script somewhere? I'm using perl scripts to kick off my backup commands.
Mysql 4.1.16 Win32.msi Error Message
I have downloaded mysql 4.1,16 win32.msi for use with sam broadcaster. The download and set up were successfull but when I try to execute I get: mysql can not start error 0.
Installing Mysql-noinstall-4.1.11-win32.zip On Windows XP
I unzip the file "mysql-noinstall-4.1.11-win32.zip" and extracted to " C"/mysql then, i did a "c:mysqlinmysqld --console" The "red light turned to green light on the mysqladmin" so, i assume mysql is connected. when i try to test the mysql by "phpinfo() " The information about mysql didnt not show up on the firefox. Does anybody know why? any configuration that i should do?
Works
I have this and it works just fine but I cant help but think there is a much better way of accomplishing the same thing in one sweep verses 6 PHP Code: mysql_query("update residential set bed='1' where bed like 'ONE%'"); mysql_query("update residential set bed='2' where bed like 'TWO%'"); mysql_query("update residential set bed='3' where bed like 'THREE%'"); mysql_query("update residential set bed='4' where bed like 'FOUR%'"); mysql_query("update residential set bed='5' where bed like 'FIVE%'"); mysql_query("update residential set bed='6' where bed like 'SIX%'");
Works In MYSQL 4.1 But Not In 5.0
MySQL 1054 - Unknown COLUMN 'p.manufacturers_id' IN 'on clause' SELECT count(*) as total FROM products p, categories c, products_to_categories p2c LEFT JOIN manufacturers m on (p.manufacturers_id = m.manufacturers_id), products_description pd WHERE c.categories_status=1 AND p.products_id = p2c.products_id AND c.categories_id = p2c.categories_id AND p.products_status = Ƈ' AND p.products_id = pd.products_id AND pd.language_id = Ƈ' Here is the query in PHP PHP "select p.products_id, pd.products_name, p.products_image, p.products_price, p.products_tax_class_id, p.products_date_added, p.manufacturers_id, m.manufacturers_name from " . TABLE_PRODUCTS . " p, " . TABLE_CATEGORIES . " c, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c left join " . TABLE_MANUFACTURERS . " m on (p.manufacturers_id = m.manufacturers_id), " . TABLE_PRODUCTS_DESCRIPTION . " pd where c.categories_status=1 and p.products_id = p2c.products_id and c.categories_id = p2c.categories_id and p.products_status = Ƈ' and p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "' order by p.products_date_added DESC, pd.products_name";
How Exactly The LIKE Keyword Works?
I have a table named Inventory and have 3 items in it containing the work w069. I want to run a query to return the three items. My query: Select * from Inventory where Description Like 'w069' It doesn't seem to work, returning zero row.
UNION - Works In 4.0.16, Not In 4.1.8
I have a query that works in 4.0.16 on my web host, but not 4.1.8 on my dev. box. Web host is upgrading in 10 days. Notes: Server language is ColdFusion gamedate is type DATE SELECT DISTINCT gamedate FROM schedule WHERE gamedate >= now() UNION ( (SELECT DISTINCT gamedate FROM schedule WHERE gamedate < now() ORDER BY gamedate desc LIMIT 1) ORDER BY gamedate asc LIMIT 3 The goal is to select the most recent gamedate prior to "today" and the next two game dates including "today".
SSN Changes In Database But Still Works As Key?
I have a ssn field in a table but somthing happens to the data. I use an update to enter the data and set the value to 123-12-1234 for a test but when I look in the table or I get the record from a record set it come out like -1123. Why is this? But when I run a query and ask it to return all records which have a ssn of 123-12-1234 it returns the correct record. If this is correct then how can I display the ssn number in a java text field.
How Exactly The LIKE Keyword Works?
I have a table named Inventory and have 3 items in it containing the work w069. I want to run a query to return the three items. My query: Select * from Inventory where Description Like 'w069' It doesn't seem to work, returning zero row.
How Decimal Works
Say that we have an variable that is var1 = 3 var2 = 3.65 var3 = var1 * var2 '--- Sum = 10.95 Now my Question! How do I input this variable into MySQL in a COL whit DECIMAL (10,2)? I only get the result 10.00 in the COL? It seams that MySQL round every resout I get to .00 at the end. If I make an varible hard ex. var3 = "10.95" that works but if I convert an numeric variable to string it doesnt?!?!?! ex. var4 = cstr(var3)
UPDATE Works In MS SQL
I use the following stament work with MSSql, but not MySql, why ? Update mytable set mycol = 'my_Text' + mycol Failed, mycol is varchar
MySQL Delete: Works In Php 5 But Not Php 4?
I've developed a small login system using Xampp on my local machine. Everything is running great except when the admin tries to delete something. Apparently I have the wrong syntax for my deletion in mysql. Here's my original delete statement (from mysql5): DELETE at.* FROM access_table AS at WHERE at.client_id=2 And here's the error I get from mysql4 (I ran the command in phpmyadmin console): #1066 - Not unique table/alias: 'at' So I removed the aliases and re wrote my command as such: DELETE * FROM access_table WHERE at.client_id=2 And got the following error from php4: #1064 - You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '* FROM access_table WHERE at.client_id=2' at line 1
SHOW DATABASES Works In 4.0.14
I've been trying to solve this problem for a long time. Only thing I did when upgrading from 3.25 to 4.0.14 I took the default my.cnf. I did not convert the privilege tables with mysql_fix_privilege_tables. Suddenly, the mysql started to show all databases to all users (even though the user had access denied and could not do show tables on them). So I started to find help and tried the mysql_fix_privilege_tables. It didn't work properly (more than just access denied and errors, that are ok) so I did the changes manually conforming to source code of mysql_fix_privilege tables. PhpMyAdmin stopped its warning about privilege tables not conforming to current mysql version. Everything seemed ok except that SHOW DATABASES still worked. The users naturally all have Show_db_priv="N" in the tables. Also trying "safe_show_database", "skip_show_database" in my.cnf and "--skip-show-database" witch mysqld didn't help.
SHOW DATABASES Works In 4.0.14
I've been trying to solve this problem for a long time. Only thing I did when upgrading from 3.25 to 4.0.14 I took the default my.cnf. I did not convert the privilege tables with mysql_fix_privilege_tables. Suddenly, the mysql started to show all databases to all users (even though the user had access denied and could not do show tables on them). So I started to find help and tried the mysql_fix_privilege_tables. It didn't work properly (more than just access denied and errors, that are ok) so I did the changes manually conforming to source code of mysql_fix_privilege tables. PhpMyAdmin stopped its warning about privilege tables not conforming to current mysql version. Everything seemed ok except that SHOW DATABASES still worked. The users naturally all have Show_db_priv="N" in the tables. Also trying "safe_show_database", "skip_show_database" in my.cnf and "--skip-show-database" witch mysqld didn't help. All *.frm files in mysql database have the same md5 as those generated by scripts/mysql_install_db.
Exporting MS Works For MySQL
I have a MS Works database and I can't find anything useful on the PHP site for working with this type of database. I did a quick search and it seems that it can be exported for OoenOffice.org and other spreadsheet database programs but none of them give a method. Mostly selling books and MS Access. If there is a way to access the .MWD or .DBF Microsoft works files with PHP that would be great. If that's not possible, preferably not, I'd rther switch to MySQl easily if possible. I'm still looking but it's not looking good.
Mysql.exe Sort Of Works
I have just installed MySQL (not an easy thing to do). I also have installed PHP. I use Dreamweaver8 for 2 static sites, and eventually will figure out how to use that with PHP/MySQL. Everything seems to work fine, and I'm working my way through Janet Valade's book, "PHP and MySQL for Dummies." Everything I have tried in the book works perfectly except for the mysql.exe command. I am in the correct folder and type mysql.exe -u root -p and am prompted for my password. When I enter my password the cursor moves to the next line and just sits there. Nothing happens. Fortunately, the window is not frozen and I can just close it.
Suddenly A Script No Longer Works
I always get the following message when starting a search in my database: Search for titles in the mylibrary database. Search for titles beginning with a:
V. 4.1.7 + Php4 Works, + Php5 Problems
I am running: Mac OS X 10.3.7 apache 2.0.52 MySQL 4.1.7 php 4.9.3 & php 5.0.3 I have an html form that "POST"s data to a db. I have a "GET" script to repopulate form for editing. Everything works fine with php 4.9.3. With php5.0.3 the data is "POST"ed just fine (I used a different GUI app to check) When I try to "GET" said data, form is returned empty? I have all error reporting turned on = nothing. I have all backwards-compatibility directives in php.ini config file turned on.
Two Different Websites Connected To One Database But Only One Works...
I have been recently having problems transferring my website from one domain name to another. The first domain name was used whilst at uni, but the second is my own perosnal website. One the original website, the MySQL database allows the user to login and register new users without any problems. However, the second website does not allow me to do this. I would consider myself a newbie when its comes to MySQL so I was wondering if the community could help me out on this one. Both websites are hosted by the same company, and both websites use the same database but my limited knowledge cannot solve this problem. Are there certain permissions I need to set or something? Can anyone help me out on this one?
Delete Using Multiple Table: Works On 4.1.20, But Not On 4.0.16
I've a simple delete query delete from joingrp as J using joingrp as J,msggrp as M where J.msgid=M.msgid and M.parent!=0 When I tried it on phpMyadmin at ixweb, having mysql-4.1.20, it works as desired. But when I tried it on phpMyadmin at iPowerweb, having 4.0.16, it says #1064 - You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'as J using joingrp as J,msggrp as M where J.msgid=M.msgid Can I solve this without using any server-side loops?
My MySQL Back-end Works Very Slow
I have installed my MySQL Server in a Window XP platform running in a Pentium4 machine. When I access the database on the machine, it is working in a normal speed. But when I access the database from a client machine (still running in windows platform), it runs very slow.
Can't Update Multiple Rows Via PHP, But Works In PhpMyAdmin
My php script will update 1 row fine, but fails on 2. However, the exact same query works when pasted into phpMyAdmin. THIS QUERY WORKS BOTH IN MY PHP AND PHPMYADMIN: $sql = "update table set color='red' where id='1';"; $sql_do = mysql_query($sql); THIS QUERY WORKS ONLY IN PHPMYADMIN: $sql = "update table set color='red' where id='1'; update table set color='green' where id='2';"; $sql_do = mysql_query($sql); I know the second query is correct, because when I copy it from my php code and paste it into phpMyAdmin, it works. But only the first query, with 1 row update, works from my php code.
Quering Works Except Need To Sort Results By Other Table...
I have the following query: SELECT plugin_id FROM tc_plugin_lists WHERE (page_id='1' AND position='0') ORDER BY tc_plugins.sort_number ASC; This almost works, the problem is the ORDER BY clause. It should order the results by the sort_number field from another table called tc_plugins. Now it throws an error... SELECT items FROM other table ORDER BY other tables field values where field is same as in 'items' ASC ?
Mysql Mysql-4.1.10-win32 Problem
I installed <b> mysql-4.1.10-win32</b>in the place of mysql 4 beta ..after my installation i am getting the message which when i try to connect php into mysql the message is Warning: mysql_connect(): Client does not support authentication protocol requested by server; consider upgrading MySQL client
Using "WHERE LIKE '%Word'" That *will* Use An Index... Works But Feels Stupid!
FYI, I'm using INNODB. Let's say I have a table with a city column containing 30,000 records, and I want to provide a search form 'starts with' and 'ends with fields. So a user would supply the following: Starts with: Cha Ends with: tte And the search would find a record such as 'Charlotte' The 'starts with' search can use an index (eg, LIKE 'Cha%'), but ends with can't (eg, LIKE '%tte'). A solution seems to be to create a city_reverse column, add a unique index on that, then perform an 'ends with' search on the city names in reverse. For instance, the 'Charlotte' record would be stored in the city_reverse column as such: 'ettolrahC' ...and I'd perform an 'ends with' search using the unique index: LIKE 'ett%' The above works, but it feels stupid, and adds weight to the database. Is there an alternative?
Free Mysql GUI Mysql "client" For Win32
I'm currently working on re-engineering a web stack completely to use mysql as a back end instead of (shiver) a bunch of Access files. I've used mysql for years both personally and professionally, but being a UNIX dork I've almost exclusively done so from the command line. Whenever I've needed something a little more user-friendly than that, I've installed a web tool like phpmyadmin. However in this case, I'm working in an all-Windows shop (mostly server 2003) and I know that I'm going to be passing this on to someone in a couple years. As I document various tasks, I'd like to use a desktop client with a GUI interface for doing things like "browsing" the database, modifying stuff now and then, etc. I see that mysql.com has a nice "administrator" and "query browser" available and they're pretty nice - but neither is really what I'm looking for in terms of something that has a GUI interface and actually manipulates the data itself. Unfortunately I cannot count on a successor knowing much SQL or being comfortable on the command line. I'm guessing there are many free tools out there but would love to start out on whatever people who already love to use such things find the most mature, featureful, easy to use, etc. So, suggestions?
Error With SQL Statement When Using MySQL 5.0.24 (Works Fine In MySQL 4.0)
Here is my query that worked in mySQL 4.0 but not in MySQL 5.0.24: INSERT INTO magtallynew SET magempnum=?', magcentre='YVRRC', entrydate=��-08-15', empnum=?', empcentre='YVRRC', connection='Rockwell', service='Express', region='dom', callertype='CSR', otherdept='', transferredcall='No', directrespdept='No', station='Not Applicable', withoutmagassist='Yes', category='Accounting', issue='Advised On Contact', comments='test' Here is the error message I get: #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'connection='Rockwell', service='Express', region='dom', callertype='CSR', otherd' at line 1
UNION, Individually Works Fine, But Not In Union
Well, I am using an UNION, and while both of the queries works fine while used individually, they don't work while in the UNION. Here is the code - PHP ( SELECT * FROM job WHERE date_fin !=0000-00-00 ORDER BY date_fin ASC ) UNION ( SELECT * FROM job WHERE date_fin =0000-00-00 ORDER BY date_creation ASC ) What do u think guys? Note : MySQL version 4.1.21 Note : Not working means, this part is not working => 'ORDER BY date_fin ASC', means, the returned results are not ordered as I want. MySQL doc. tells, To apply ORDER BY or LIMIT to an individual SELECT, place the clause inside the parentheses that enclose the SELECT: (SELECT a FROM t1 WHERE a=10 AND B=1 ORDER BY a LIMIT 10) UNION (SELECT a FROM t2 WHERE a=11 AND B=2 ORDER BY a LIMIT 10);
User Problems... Only Root User "works".
i have been trying to figure this strange problem out for a week or so. here it is. i have a set of users with various permissions for different reasons. about 2 weeks ago, my hardware suffered a fairly nasty failure. i recovered everything. things seemed to work out. i didnt think to check my phpBB forums or my blog (or other mysql based stuff). never had any problems with the DB... so, maybe i am missing something simple here. i hope so. what my users can do: they can log in via command line, a gui i use on mac os x and it does not matter if it is local, or remote. they work just fine. what all but one users cannot do: none of my users can run phpbb or the blog stuff.. except for the root user. any other user returns the error message written in the code of which ever script i try to access telling me that "could not connect to DB" etc.. root works fine. now, i thought maybe it was a problem with the forums and other stuff. but i cant be. same thing happens with all things... even a game server i occasionally run that keeps account info in a DB. all these users are set up properly and have worked just fine in the past. nothing new has been installed, no conf changes..im at a loss...
How Can I Make A Query Like Microsoft Access, And A Query From A Query
I am new to MYSQL and am trying to understand how to make queries... I am moving from Microsoft Access where it is GUI driven and easy! I can make a simple single query using MYSQL Query Browser, say: qry1: SELECT ID, Area FROM data GROUP BY Area How can I store this as a query inside MYSQL, rather than having to code it each time? In Microsoft Access I could enter a variable ($VARIABLE) and then pass by code to the query: qry2: SELECT ID, $VARIABLE FROM data GROUP BY $VARIABLE How can I store this as a query and then pass the variable from code? In Microsoft Access I could base a query on the results of another query, so following example above: qry3: SELECT qry1.Area, data.ID FROM qry1 INNER JOIN data ON qry1.Area = data.Area; How can I store this as a query in MYSQL.
How To Create Efficient MySQL Query From A Pseudo Query
I'm trying to build a webapplication where users can search for a person having a particular preference for color and material. To store this information I use the following structure (a MySQL dump can be found at the end of this post): *table person with fields: -persid: autoincrement id -name: name of the person *table material with fields: -materialid: autoincrement id -material: name of the material eg "wood" *table color with fields: -colorid: autoincrement id -color: name of the color eg "green" *table persmaterial with fields: -persmatid: autoincrement id -persid: link to table person -materialid: link to table material *table perscolor with fields: -perscolorid: autoincrement id -persid: link to table person -colorid: link to table color In the webapplication the search can be entered by the users as a kind of pseudo query: (color=red OR color=blue) AND color=green AND material=iron My question is: how can I automatically transform this pseudo query into an efficient MySQL query? I have tried out some different options: Option 1: (SELECT p.persid FROM person p, perscolor pc, persmaterial pm WHERE p.persid=pc.persid AND (pc.colorid=1 OR pc.colorid=2) AND p.persid=pm.persid AND pm.materialid=2 GROUP BY p.persid HAVING (count(DISTINCT pc.colorid)=2 AND count(DISTINCT pm.materialid)=1)) UNION (SELECT p.persid FROM person p, perscolor pc, persmaterial pm WHERE p.persid=pc.persid AND (pc.colorid=2 OR pc.colorid=3) AND p.persid=pm.persid AND pm.materialid=2 GROUP BY p.persid HAVING (count(DISTINCT pc.colorid)=2 AND count(DISTINCT pm.materialid)=1)) Remarks: *I do not see how to turn a general pseudo query into a query like the one in option 1, except for turning the pseudo query into a sum of products form where the sulms would correspond to the UNIONs. IS there a clever way to obtain such a sum of products form from an arbitrary pseudo query? Option 2: SELECT persid FROM person p WHERE (EXISTS(SELECT * FROM perscolor pc WHERE pc.colorid=1 AND p.persid=pc.persid) OR EXISTS(SELECT * FROM perscolor pc WHERE pc.colorid=3 AND p.persid=pc.persid)) AND EXISTS(SELECT * FROM perscolor pc WHERE pc.colorid=2 AND p.persid=pc.persid) AND EXISTS(SELECT * FROM persmaterial pm WHERE pm.materialid=2 AND p.persid=pm.persid) Remarks: *very easy to get from pseudo query to MySQL query but what about performance? Option 3: SELECT p.persid FROM person p, perscolor pc, persmaterial pm WHERE p.persid=pc.persid AND (pc.colorid=1 OR pc.colorid=2 OR pc.colorid=3) AND p.persid=pm.persid AND pm.materialid=2 GROUP BY p.persid HAVING sum(case when pc.colorid in (Ƈ',Ɖ') then 1 else 0 end) >= 1 AND sum(case when pc.colorid=ƈ' then 1 else 0 end)>=1 AND sum(case when pm.materialid=ƈ' then 1 else 0 end)>=1 Remarks: *this option requires the pseudo query to be turned into a product of sums form; again is their a clever way to obtain such a form; Option 4 SELECT DISTINCT pc1.persid FROM perscolor pc1 INNER JOIN perscolor pc2 ON pc1.persid=pc2.persid AND pc2.colorid=2 INNER JOIN persmaterial pm1 ON pc1.persid=pm1.persid AND pm1.materialid=2 LEFT OUTER JOIN perscolor pc3 ON pc1.persid=pc3.persid AND pc3.colorid=1 LEFT OUTER JOIN perscolor pc4 ON pc1.persid=pc4.persid AND pc4.colorid=3 WHERE COALESCE(pc3.persid,pc4.persid) IS NOT NULL Remarks: *this option requires the pseudo query to be turned into a product of sums form Option 5: SELECT p.persid FROM person p, persmaterial pm,perscolor pc1,perscolor pc2,perscolor pc3 WHERE p.persid=pm.persid AND p.persid=pc1.persid AND p.persid=pc2.persid AND p.persid=pc3.persid AND (pc1.colorid=1 OR pc2.colorid=3) AND pc3.colorid=2 AND pm.materialid=2 GROUP BY p.persid Remarks: *very easy to get from pseudo query to MySQL query but what about performance? -- phpMyAdmin SQL Dump -- version 2.6.1 -- http://www.phpmyadmin.net -- -- Host: localhost -- Generation Time: Oct 19, 2006 at 01:13 PM -- Server version: 4.1.9 -- PHP Version: 4.3.10 -- -- Database: `aston` -- -- -------------------------------------------------------- -- -- Table structure for table `color` -- CREATE TABLE `color` ( `colorid` int(11) NOT NULL auto_increment, `color` varchar(30) NOT NULL default '', PRIMARY KEY (`colorid`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ; -- -- Dumping data for table `color` -- INSERT INTO `color` VALUES (1, 'red'); INSERT INTO `color` VALUES (2, 'green'); INSERT INTO `color` VALUES (3, 'blue'); INSERT INTO `color` VALUES (4, 'yellow'); -- -------------------------------------------------------- -- -- Table structure for table `material` -- CREATE TABLE `material` ( `materialid` int(11) NOT NULL auto_increment, `material` varchar(30) NOT NULL default '', PRIMARY KEY (`materialid`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ; -- -- Dumping data for table `material` -- INSERT INTO `material` VALUES (1, 'wood'); INSERT INTO `material` VALUES (2, 'iron'); -- -------------------------------------------------------- -- -- Table structure for table `perscolor` -- CREATE TABLE `perscolor` ( `perscolorid` int(11) NOT NULL auto_increment, `persid` int(11) NOT NULL default Ɔ', `colorid` int(11) NOT NULL default Ɔ', PRIMARY KEY (`perscolorid`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=7 ; -- -- Dumping data for table `perscolor` -- INSERT INTO `perscolor` VALUES (1, 1, 1); INSERT INTO `perscolor` VALUES (2, 1, 2); INSERT INTO `perscolor` VALUES (3, 2, 1); INSERT INTO `perscolor` VALUES (5, 3, 3); INSERT INTO `perscolor` VALUES (6, 3, 2); -- -------------------------------------------------------- -- -- Table structure for table `persmaterial` -- CREATE TABLE `persmaterial` ( `persmatid` int(11) NOT NULL auto_increment, `persid` int(11) NOT NULL default Ɔ', `materialid` int(11) NOT NULL default Ɔ', PRIMARY KEY (`persmatid`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=6 ; -- -- Dumping data for table `persmaterial` -- INSERT INTO `persmaterial` VALUES (1, 1, 1); INSERT INTO `persmaterial` VALUES (2, 1, 2); INSERT INTO `persmaterial` VALUES (3, 2, 1); INSERT INTO `persmaterial` VALUES (5, 3, 2); -- -------------------------------------------------------- -- -- Table structure for table `person` -- CREATE TABLE `person` ( `persid` int(11) NOT NULL auto_increment, `name` varchar(30) NOT NULL default '', PRIMARY KEY (`persid`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ; -- -- Dumping data for table `person` -- INSERT INTO `person` VALUES (1, 'john'); INSERT INTO `person` VALUES (2, 'emily'); INSERT INTO `person` VALUES (3, 'liz');
Simple Sql Question: Using A Query Result As A Query Variable
EDIT: it works now, I had an error in my code, not my method. I have a very simple question. I have 2 tables: 'users' and 'posts' with the following structure: users: id, username, email_address posts: id, user_id, post_title, post_text in a my own mind's mysql, I would like to: SELECT posts.id, posts.user_id, posts.post_title, posts.post_text users.username FROM users, posts WHERE posts.user_id = users.id I usually do one query for the post data, and then, based on the use_id record, do another of the users table, but today, I'm being forced to do them in one swoop.
Query Based On Results Of A Previous Query
So far I have managed to construct one query which gives me all individuals that have one of three titles. based on this I now want to find all the individuals that are affiliated to those listed in the first query ....
|