CanMan2004 Posted July 14, 2006 Share Posted July 14, 2006 HiI have a very complex query which currently looks in a table called 'users' and I want to be able to query a 2nd table (which is called "people") in the same statement, the 'people' table has the same fields as the 'users' table is currently searches.How can I change the query to look in a 2nd table? My query is[code]$sql = "SELECT * FROM users";if ($_GET['name'] != ""){$sql =$searchsql." WHERE show = '1'";}$sql =$searchsql." LIMIT $from, $mr";[/code]Any help would be great.Thanks in advanceDave Quote Link to comment https://forums.phpfreaks.com/topic/14599-two-tables/ Share on other sites More sharing options...
Oldiesmann Posted July 14, 2006 Share Posted July 14, 2006 [code]$sql = "SELECT u.*, p.* FROM users AS u, people AS p";if($_GET['name'] != ""){$sql .= "WHERE u.show = '1' OR p.show = '1'";}$sql .= " LIMIT $from, $mr";[/code]When looking at the results, remember that columns from users will be prefixed with a "u." and columns from people will be prefixed with a "p.". Quote Link to comment https://forums.phpfreaks.com/topic/14599-two-tables/#findComment-58022 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.