0
selectをいくつか作成していますが、サブクエリの値を使用してwhereステートメントを無視するように見える方法が見つかりませんでした。 私は1つのコンテンツテーブル、2つの他のテーブルを結合で2つの結合テーブル、もう1つのテーブルを結合wjth最初に直接持っていた。サブクエリを使用したMySql SELECTが期待どおりに動作しない
が、私はいくつかのソリューションを試みたが、これは1
select * from (SELECT a.idcontents, a.title, concat(a.filepath, '/', a.filename) as file,
a.captured_on, a.starred, a.file_type,
@PL:=(select GROUP_CONCAT(CONCAT(p.idplaces, '-', p.place) SEPARATOR ', ') from places p where a.idplaces=p.idplaces) as places,
@AL:=(select GROUP_CONCAT(CONCAT(al.idalbum, '-', al.album) SEPARATOR ', ') from album al, join_album_contents am where am.idalbum=al.idalbum and am.idcontents=a.idcontents) as album,
@PE:=(select GROUP_CONCAT(CONCAT(an.idpeople, '-', an.person) SEPARATOR ', ') from people an, join_people_contents ao where ao.idpeople=an.idpeople and ao.idcontents=a.idcontents) as people
FROM contents a) t
WHERE (@PE is null OR @AL is null OR @PL=1)
最新のものですが、私は成功せず、あまりにも
SELECT a.idcontents, a.title, concat(a.filepath, '/', a.filename) as file,
a.captured_on, a.starred, CONCAT(p.idplaces, '-', p.place) as places,
(select GROUP_CONCAT(CONCAT(al.idalbum, '-', al.album) SEPARATOR ', ') from album al, join_album_contents am where am.idalbum=al.idalbum and am.idcontents=a.idcontents) as album,
(select GROUP_CONCAT(CONCAT(an.idpeople, '-', an.person) SEPARATOR ', ') from people an, join_people_contents ao where ao.idpeople=an.idpeople and ao.idcontents=a.idcontents) as people
FROM contents a, places p
WHERE a.idplaces=p.idplaces
and (@album IS NULL OR @people IS NULL or p.idplaces=1)
これを試してみました、句は常に無視されているようで、結果は1かのレコードを含んでいますすべての部分が内部で句をとります。 レコードのみが正しく表示されます。
この問題を解決するソリューションがあるかどうかを知るだけです。
解決策は以下のコメントにあります!
t.people is null or t.album is null or t.places='1'
ありがとう!!
出力は、あなたが実際にそのサンプルに基づいて、クエリから取得するには、関連するテーブルごとにサンプルデータを入力してください、そしてどのようなあなたが得ることを望みます。 – trincot
最初の質問で 't.peopleがヌルかt.albumがヌルかt.place = 1'と言うのはなぜですか?変数は必要ありません。 – shawnt00
ありがとうshawnt00 !!!!それは作品です:)私は2日間このために失った!本当にありがとう – Dierre