Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6888887
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:05:05+00:00 2026-05-27T06:05:05+00:00

I am simply trying to query a table to return a boolean value, which

  • 0

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
)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T06:05:06+00:00Added an answer on May 27, 2026 at 6:05 am

    Nothing going wrong, Actually you are trying to select userid, artistid from $sTable4 where 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 think where exists will work for you like this:

    SELECT ab.artistid
    FROM $sTable4 AS ab
    WHERE exists 
    (
        select artistid 
        from $sTable4 b 
        where b.userid=$userid AND b.artistid=$artistid
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a simple database table using the PHP MySQL query Create
I'm trying to perform a simple LINQ query on the Columns property of a
I'm simply trying to convert a CGEventTimestamp (which is an unsigned 64-bit integer roughly
I am trying to achieve a query which includes a subquery which itself includes
How can I write DAO method which will return as a result only first
I'm trying to write a query that will return all QUERY_ID values alongside all
I'm trying to return the rowcount from a SQL Server table. Multiple sources on
I am trying to convert a query to return as xml in the correct
I'm trying to query my database and return with entries that are within a
I am trying to develop a T-SQL query which will do the following: ROUND(100

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.