Welcome to WebmasterWorld Guest from 54.226.130.194

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Searching Two Mysql Tables

     

matthewamzn

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

10+ Year Member



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

LifeinAsia

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

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



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