I have an SQL statement:
$sql = "SELECT * FROM user_events WHERE userID =" . $uid . " OR groupID = (IN ($gId) WHERE userID IS NULL) ORDER BY timestamp DESC";
This looks like this when printed:
SELECT * FROM user_events WHERE userID = 34 OR groupID =(IN (44,45) WHERE uID IS NULL) ORDER BY timestamp DESC
What I'm trying to do is select from the database any row where either the userId matches a specific variable or where the groupID matches a CSV variable where the userID is NULL.
Can anyone explain what I'm doing wrong here? I'm quite stuck!
INas an operator when dealing with comma-separated lists. Use=as an operator when comparing exact values. UseLIKEas an operator when comparing case-insensitive values and wildcards. They are all comparison operators and should be used as such (just like in mathematics).$uidinside a query should set your hair on fire.