piyush23424 Posted February 18, 2010 Share Posted February 18, 2010 Hi, i am using the following query to fetch records from the database $q="select * from the list where address='%$searchString'"; The above query is fetching the matching results. Now what i want is it should also fetch the other records having same city id as that of the resultant row. city_id is a other column in the list table. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/192513-mysql-query/ Share on other sites More sharing options...
sader Posted February 18, 2010 Share Posted February 18, 2010 $q="select * from the list where address='%$searchString' and city_id=$citi_id"; Quote Link to comment https://forums.phpfreaks.com/topic/192513-mysql-query/#findComment-1014365 Share on other sites More sharing options...
piyush23424 Posted February 18, 2010 Author Share Posted February 18, 2010 $q="select * from the list where address='%$searchString' and city_id=$citi_id"; Thanks for replying but you are taking my question in wrong way. what i need is first it will find the result with address and then it will check the cityid of the resultant row. after that it will fetch all other records from list table having same cityid as that of resultant row's city id. i know it can be done with nested select query but i don't know how to write that. ? Quote Link to comment https://forums.phpfreaks.com/topic/192513-mysql-query/#findComment-1014388 Share on other sites More sharing options...
mapleleaf Posted February 19, 2010 Share Posted February 19, 2010 Sounds like you need a subquery Select * from the list WHERE city_id = '(select city_id from the list where address='%$searchString')' ; My syntax is almost certainly wrong but you get the idea and can probably look up subqueries somewhere. Quote Link to comment https://forums.phpfreaks.com/topic/192513-mysql-query/#findComment-1014626 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.