rjorge
asked on
How to retrieve query results when count() = 0 ?
Greetings,
I have the following (similar) structure :
create table players (
ownerid int,
name varchar(10)
)
create table games (
gameid int,
name varchar(255)
)
create table gameowner (
ownerid int,
gameid int
)
I want to make a query where I can list all the owners with less than 'x' games, including those that have none. I am having some problems with the second part. would greatly appreciate your help.
r
I have the following (similar) structure :
create table players (
ownerid int,
name varchar(10)
)
create table games (
gameid int,
name varchar(255)
)
create table gameowner (
ownerid int,
gameid int
)
I want to make a query where I can list all the owners with less than 'x' games, including those that have none. I am having some problems with the second part. would greatly appreciate your help.
r
ASKER
Hi Barry,
I wonder whether there might be a problem when the result of the join is a null line, because there is no line matching "join gameowner on players.ownerid = gameowner.ownerid", (e.g. there is an id on players for which there is no entry on gameowner table). As I see it may result on on a empty/null set. I still want to see those entries. See example output below.
name | games
john 1
jack 0
sam 2
I wonder whether there might be a problem when the result of the join is a null line, because there is no line matching "join gameowner on players.ownerid = gameowner.ownerid", (e.g. there is an id on players for which there is no entry on gameowner table). As I see it may result on on a empty/null set. I still want to see those entries. See example output below.
name | games
john 1
jack 0
sam 2
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Don is correct. Use a left (or outer) join.
from players
join gameowner on players.ownerid = gameowner.ownerid
where games < 5
group by players.name,games