Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

combine search on 2 tables

Status
Not open for further replies.

effennel

Technical User
Joined
Oct 15, 2002
Messages
60
Location
CA
Is there a simpler/more compact way to code this?

The query is the same on the 2 tables:

$sql = "SELECT id FROM users_intake WHERE users_id=5 AND timeStamp LIKE '2005%'";
$result = mysql_query($sql);
$inside1 = mysql_fetch_object($result);

$sql = "SELECT id FROM users_state WHERE users_id=5 AND timeStamp LIKE '2005%'";
$result = mysql_query($sql);
$inside2 = mysql_fetch_object($result);

if (!$inside1 and !$inside2) {
echo "no";
} else {
echo "yes";
}

Thanks
FnL
 
Maybe something like this:
$sql = "SELECT id FROM users_intake WHERE users_id=5 AND timeStamp LIKE '2005%' UNION SELECT id FROM users_state WHERE users_id=5 AND timeStamp LIKE '2005%'";

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thanks PH,

I'll post that on the MySQL forum since MySQL does not support UNION...

FnL
 
That is before Version 4.0.0
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top