homepage Welcome to WebmasterWorld Guest from 54.211.68.132
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Searching Two Mysql Tables
matthewamzn

5+ Year Member



 
Msg#: 3875305 posted 4:50 pm on Mar 20, 2009 (gmt 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";

 

LifeinAsia

WebmasterWorld Administrator lifeinasia us a WebmasterWorld Top Contributor of All Time 5+ Year Member



 
Msg#: 3875305 posted 5:00 pm on Mar 20, 2009 (gmt 0)

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

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved