Welcome to WebmasterWorld Guest from 54.198.143.210

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Searching Two Mysql Tables

     
4:50 pm on Mar 20, 2009 (gmt 0)

Full Member

10+ Year Member

joined:Jan 27, 2005
posts: 229
votes: 0


How can I combine two searches from different tables into one query?

$query_one = "SELECT * FROM `v_inv` WHERE MATCH (color,make,model,intcolor,category) AGAINST ('{$search}') AND public = 1 ORDER BY date";
$query_two = "SELECT * FROM `v_pvi` WHERE MATCH (color,make,model,intcolor,category) AGAINST ('{$search}') AND public = 1 ORDER BY date";

5:00 pm on Mar 20, 2009 (gmt 0)

Moderator from US 

WebmasterWorld Administrator lifeinasia is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Dec 10, 2005
posts:5701
votes: 87


SELECT *
FROM `v_pvi`
WHERE MATCH (color,make,model,intcolor,category) AGAINST ('{$search}') AND public = 1
UNION
SELECT *
FROM `v_pvi`
WHERE MATCH (color,make,model,intcolor,category) AGAINST ('{$search}') AND public = 1

The field names must be identical in each table. Otherwise, just select the fields that do have identical names (or use aliases).

 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members