mysql - check if data exists across multiple tables

Posted by Dd Daym on Stack Overflow See other posts from Stack Overflow or by Dd Daym
Published on 2012-12-16T22:49:58Z Indexed on 2012/12/16 23:03 UTC
Read the original article Hit count: 150

Filed under:
|
|
|
|

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

© Stack Overflow or respective owner

Related posts about php

Related posts about mysql