database - Joining 3 MySQL tables to display all data -
i've read countless threads on stackoverflow regarding matters similar this, i'm struggling solve issue , understand various mysql join queries. i'm in days of learning mysql, , appreciated.
i have 3 tables:
- auction
- category
- lot
auction , category have unique primary key , auction date, category title column respectively.
lot displays lot title, lot description etc... , links auction , category table using respective id's.
i wish display lot table showing rows including auction date , category title.
my failed attempt:
select l.lotid, l.lotnumber, l.lottitle, l.lotdescription, c.categorytitle, a.auctiondate, l.estimatefrom, l.estimateto, l.photo, l.datecreated, l.lastmodified lot l join category c on l.categoryid = c.categoryid join auction on l.auctionid = a.auctionid order l.lotnumber; this acting query, i'm sure should, omitting rows whereby categorytitle , auctiondate not match
is there simple fix?
many thanks
use left join:
select l.lotid, l.lotnumber, l.lottitle, l.lotdescription, ifnull(c.categorytitle,'n/a'), ifnull(a.auctiondate,'n/a'), l.estimatefrom, l.estimateto, l.photo, l.datecreated, l.lastmodified lot l left join category c on l.categoryid = c.categoryid left join auction on l.auctionid = a.auctionid order l.lotnumber;
Comments
Post a Comment