基本的に、私はLEFT JOINテーブルを使用して、PERSONに属するINVOICEレコードを取得しています。
関連するレコードとともにテーブルの概要。
table INVOICES table GIGS table BIDS table PEOPLE
---------------- ---------------- ----------------------- ----------------
id | gig_id id | bid_id id | gig_id | person_id id
---------------- ---------------- ----------------------- ----------------
1 | 1 1 | 1 1 | 1 | 1 1
2 | 2 2 | 1 | 2 2
と私の参加クエリ...
SELECT invoices.* FROM invoices
INNER JOIN gigs ON gigs.id = invoices.gig_id
INNER JOIN bids ON bids.gig_id = gigs.id
INNER JOIN people ON people.id = bids.person_id
WHERE people.id = 2
GROUP BY invoices.id
そして返された結果...
INVOICE RESULT
--------------
id
--------------
1
実際には、請求書はありpeople.id=2
ませんが、上記の結合クエリは、あたかもあるかのように結果を返しました。請求書がない場合に空に戻るようにするにはどうすればよいですか?
これに関するヒントは大歓迎です!