Jump to content

[help] Joining two queries?


csj

Recommended Posts

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? ;D

Link to comment
https://forums.phpfreaks.com/topic/88846-help-joining-two-queries/
Share on other sites

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

 

  • 3 weeks later...

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

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.