First post, be gentle! My SQL knowledge is average, at best.
I have 2 tables with no direct relationship to each other.
- TableA ("CustomerWishList") with columns "bookID", other-book-data, etc etc etc
- TableB ("CustomerOwned") with columns - "bookID", other-book-data, etc etc etc
A book could be in one, both, or none of those tables.
I need to create SQL statement that counts the number of "bookID='data'"
occurrences in either TableA or TableB.
So far using PHP I'm searching TableA "bookID"
column first, and then if nothing found, searching TableB "bookID"
column next ... it works, but is inefficient, and am convinced there must be a better way.
JOIN statements don't seem to apply here? - I could be wrong.
UPDATED
Psuedo PHP code I'm currently using:
$total=SELECT COUNT(*) FROM CustomerWishList WHERE BOOKID=1234
if ($total==0) {
$total2=SELECT COUNT(*) FROM CustomerOwned WHERE BOOKID=1234
}
return $total2;