hvle Posted August 2, 2006 Share Posted August 2, 2006 hi guys,i have a table classified_city which containsidn: intergername: varcharsubcity_idn: integerI have this query:"select name from classified_city where idn=(select subcity_idn from classified_city where idn='2')"This query does work on my local server, which run mysql 4.1.12 but does not work on remote server which I presume running a older version. (i do not know which version they're running).Can anybody correct the syntax of that query so it would work with older version?Thanks Quote Link to comment Share on other sites More sharing options...
fenway Posted August 2, 2006 Share Posted August 2, 2006 You might as well use a self-join (UNTESTED):[code]select c1.name from classified_city AS c1 join classified_city AS c2 on ( c1.idn = c2.subcity_idn )where c2.idn='2'[/code] Quote Link to comment Share on other sites More sharing options...
hvle Posted August 3, 2006 Author Share Posted August 3, 2006 Thank you so much, It worked on both server, and faster too. Quote Link to comment Share on other sites More sharing options...
fenway Posted August 3, 2006 Share Posted August 3, 2006 No problem.. JOINs are almost always faster than sub-queries, more portable, and IMHO, easier to understand and maintain. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.