I’m trying to make a table show it’s full content eventhough there might be some empty cells. The table contains ten possible positions (i.e. chairman, secretary etc) in a small club. Each position refers to a member ID in a member table depending on who has been elected to said position. A position may be vacant and this is what I’m trying to accomplish. The structure (simplified) is as follows:
Table “members”
CREATE TABLE members (
id_member INT NOT NULL,
member_name VARCHAR(45),
PRIMARY KEY (id_member));
Table “positions”
CREATE TABLE positions (
id_position INT NOT NULL,
position_name VARCHAR(45),
PRIMARY KEY (id_position)
FOREIGN KEY (id_member) REFERENCES members(id_member));
Select syntax
SELECT position_name, member_name
FROM members
JOIN positions USING(id_members);
It works very well as long as there is a member on a position but if it’s vacant, that row doesn’t appear. Is there some way to make the table positions always return every row eventhough the column id_member has empty cells?
Desired result:
Chariman – Jack Carver
Secretary – Joe Hill
Accounter – NULL
Webmaster – Joanna Robson
use
LEFT JOINinstead and interchange the tableNamesTo fully gain knowledge about joins, kindly visit the link below: