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
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

 

Link to comment
Share on other sites

  • 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

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.