Its Saying I Have No Row Selected?
It's saying I have no row selected. This is the question: Find the member ID, last name, and first name of the members who have never borrowed any books in the past or currently.
Solution 1:
There's a couple of ways to do this:
You can use an anti-join, such as:
SELECT m.MEMBERID,
m.LASTNAME,
m.FIRSTNAME
FROM MEMBERS m
WHERE m.MEMBERID NOTIN (SELECTDISTINCT MEMBERID
FROM CURRENTLOAN
UNIONALLSELECTDISTINCT MEMBERID
FROM HISTORY);
Another way (and my preferred method) to do what you want is:
SELECTDISTINCT m.MEMBERID,
m.LASTNAME,
m.FIRSTNAME
FROM MEMBERS m
LEFTOUTERJOIN (SELECTDISTINCT MEMBERID
FROM (SELECT MEMBERID
FROM CURRENTLOAN
UNIONALLSELECT MEMBERID
FROM HISTORY)) u
ON u.MEMBERID = m.MEMBERID
WHERE u.MEMBERID ISNULL;
However, given the data you've shown this query, as well as your original query, should return zero rows. SQLFiddle here
Note that if you comment out the current loan to member 004, then "Joe Brown" is returned SQLFiddle here
Best of luck.
Post a Comment for "Its Saying I Have No Row Selected?"