csj Posted February 1, 2008 Share Posted February 1, 2008 I'm wondering how to go about this? I'm not sure if its even possible or if I need to use a join or something? Im using a search facility on my page. When a user types something into the search box I need it to search inside two separate tables. Can this be done? The results for the query will be run inside a while statement. I would really appreciate any help? The two individual queries look like this: $query1 = "SELECT * FROM items WHERE (item_title LIKE '% $searching %') order by item_title asc "; $query2 = "SELECT username FROM users WHERE (username LIKE '% $searching %') order by username asc"; How can I join these? Quote Link to comment Share on other sites More sharing options...
priti Posted February 1, 2008 Share Posted February 1, 2008 select i.*,u.username from items t,users u where t.item_title ='parameter' or u.username='parameter' you can try something like this according to you need it will solve your purpose . still you can wait for some mysql guru to drop in here and give you the most optimised way of doing this . Regards Quote Link to comment Share on other sites More sharing options...
JTapp Posted February 17, 2008 Share Posted February 17, 2008 csj - I have the EXACT same problem. Nobody seems to be responding to my post. The one response you got - I spent about 45 minutes on.. trying to understand what the heck they were saying. Were you ever able to figure this out? Quote Link to comment Share on other sites More sharing options...
priti Posted February 18, 2008 Share Posted February 18, 2008 considering two tables table 1:company nokia motorola table2:model id company model 1 nokia N91 Edit Delete 2 NOKIA n92 Edit Delete 3 samsung 123 Edit Delete 4 samsung 3434 Edit Delete 5 LG LG-dinamit Edit Delete 8 Motorola motoRocker Edit Delete 9 Motorola motoRocker Query: select company.name,model.company,model.model from company LEFT JOIN model on company.name=model.company where company.name="nokia" OR model.company="nokia" Output: name company model nokia nokia N91 nokia NOKIA n92 I think this works that query needed a proper way of setting joins for more info on mysql join kindly visit http://dev.mysql.com/doc/refman/5.0/en/join.html it wil help you understand what i have done here hope it help happy coding The query 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.