次の3つの表にはすべて、date_v_end有効日である「」フィールドがあります。NULLこれが現在の「良い」値であることを意味する限り。
たとえば、テーブルの現在の値を選択するには、categorie単純に実行できますSELECT * FROM categorie WHERE date_v_end IS NULL。
私は3つのテーブルを持っています:
- テーブル
categorie(英語のカテゴリ) - 表「1対多」
categorie_produit(英語のカテゴリ<=>製品) - テーブル
produit(英語の製品)
現在 のすべての、およびcategoriesそれらの1対多のクエリを作成したいのですが、カテゴリに製品がない(=行がない)場合でも、 1つの結果が必要です。produit produit_categorie
date_v_end" "フィールドを作成する前に、次のようにしました。
SELECT
c.id AS c_id,
c.titre AS c_titre,
c.description AS c_description,
cp.id_categorie AS cp_id_categorie,
cp.id_produit AS cp_id_produit,
p.id AS p_id,
p.titre AS p_titre,
p.description AS p_description
FROM categorie_produit cp
LEFT OUTER JOIN categorie c
ON c.id=cp.id_categorie
LEFT OUTER JOIN produit p
ON p.id=cp.id_produit
ORDER BY c_id,p_id;
それは魅力のように機能しました。今、私は新しい" date_v_end"フィールドでクエリを変更しようとしています。3つの句を追加しましたWHERE c.date_v_fin IS NULL AND cp.date_v_fin IS NULL AND p.date_v_fin IS NULL。そこに行きます:
SELECT
c.id AS c_id,
c.titre AS c_titre,
c.description AS c_description,
cp.id_categorie AS cp_id_categorie,
cp.id_produit AS cp_id_produit,
p.id AS p_id,
p.titre AS p_titre,
p.description AS p_description
FROM categorie_produit cp
LEFT OUTER JOIN categorie c
ON (c.id=cp.id_categorie AND c.date_v_fin IS NULL)
LEFT OUTER JOIN produit p
ON (p.id=cp.id_produit AND p.date_v_fin IS NULL)
WHERE cp.date_v_fin IS NULL
ORDER BY c_id,p_id;
これは、1つの状況を除いて正常に機能します。aがcategorie_produit あり、その " date_v_end"がない場合 :このくそー " "フィールドNULLを追加する前に、c_id、c_titre、およびc_descriptionが入力された1つの行と、他のフィールド( 、、、、、 )があります。今は結果がありません。date_v_endNULLcp_id_categoriecp_id_produitp_idp_titrep_description
クエリを変更して機能させる方法が本当にわかりません。何か案が?