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 9000367
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:18:10+00:00 2026-06-16T00:18:10+00:00

I am currently running this query inside MySQL to check if the specified values

  • 0

I am currently running this query inside MySQL to check if the specified values exists
within the table associated with them.

SELECT COUNT(artist.artist_id), COUNT(album.album_id), COUNT(tracks.track_id) 
FROM artist, album, tracks WHERE artist.artist_id = 320295 OR album.album_id = 1234 OR tracks.track_id = 809

The result I get from running this query is all 1, meaning that all the statements after the WHERE clause is true. To further check the query’s reliability, I changed the tracks.track_ = 809 to 802, which I know does not match. However the results displayed are still all 1, meaning that they were all successfully matched even when I purposefully inserted a value which would not have matched.

How do I get it to show 1 for a match and 0 for no matches within the same query?

EDIT: I have inserted an image of the query running

enter image description here

  • 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-06-16T00:18:11+00:00Added an answer on June 16, 2026 at 12:18 am

    What you do here is a join over three tables. You can see what happens, when you look at this SQL Fiddle.

    In the first select, I have left out the count, to show how the join works. You can also see how the result set changes, when you modify the where clause from or to and as @RayPaseur suggested.

    I guess, what you want, is really three separate queries

    select 'artist' as type, count(artist_id) as count
    from artist
    where artist_id = 320295
    union
    select 'album', count(album_id)
    from album
    where album_id = 1234
    union
    select 'track', count(track_id)
    from tracks
    where track_id = 809
    

    which becomes

    TYPE    COUNT
    artist  1
    album   1
    track   1
    

    Now, when you change track_id = 809 to track_id = 802, you will get

    TYPE    COUNT
    artist  1
    album   1
    track   0
    

    as a result.

    SQL Fiddle for playing.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently I'm running a MySQL query like this $query = SELECT t1.id AS 'post_id',
I'm currently running a query like this: SELECT * FROM email WHERE email_address LIKE
I am currently running this query: SELECT t.videolink, t.userid, t.tag FROM (SELECT * FROM
I have a complex select query and a huge table. I'm running this select
Evening, I'm currently running this query: SELECT `id`, `type`, `controller` FROM `urls` WHERE `url`
I am running this query SELECT sh.*, u.initials AS initals FROM database1.table1 AS sh
Here's the query I'm currently running: $result = R::getAll(SELECT * FROM vw_participantes_curso JOIN vw_cursos
I currently have this query running on my website, public function searchCandidates($type=null, $gender=null, $age=null)
Okay so, I'm currently running this code to move a bunch of data from
I have this running software that is currently being used by about 400 people.

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.