I am simply trying to query a table to return a boolean value, which seems to only ever return null.
$sTable4 consists of the columns userid & artistid
$artistid is a parameter passed in to the script (which is definitely being correctly passed)
$userid is the id of the currently logged in user.
User are able to save artists in to their favourites list.
What I want is to check this table for the currently logged in user and a specific artistid which is declared in the variable above to see if an entry exists. If it doesn’t then I want it to return null and to return ‘1’ if it does.
Any ideas where I am going wrong?
SELECT userid, artistid
FROM $sTable4 AS b
WHERE NOT EXISTS
(
SELECT artistid
FROM $sTable4 AS ab
WHERE b.userid = $userid
AND b.artistid = $artistid
)
Nothing going wrong, Actually you are trying to select
userid, artistidfrom$sTable4where they are not exists in the same table, so what do you expect and how would you select them if they are not exists?!! I think you are missing something in your query, becouse this check will always return null as they are exists, so it won’t select them. So i thinkwhere existswill work for you like this: