-1

質問があります:

select
p.id AS id,
p.text AS text,
p.date AS date,
k.color AS color,
...

FROM

cform_mba_contacts p,
cform_mba_contacts_category_links o,
cform_mba_contacts_status k,
...

where

p.id_peoples = ".$this->id." AND
o.id_contacts = p.id AND
o.id_status = k.id AND
...

order by p.date

このクエリは、新しい条件が導入される前は完全に機能していました。その条件でそのデータを選択する必要がありp.id_peoples = ".$this->id.". 使用しようとしましUNIONたが、うまくいきませんでした。どうやってやるの?

アップデート

UNION 演算子に関する追加のドキュメントを読んで問題を解決します

4

4 に答える 4

1

たぶんあなたが欲しいのはUNIONALLです。

于 2012-09-06T07:44:49.317 に答える
0

私はあなたがこれを探していると思います:

WHERE 1 = 1
AND (@id IS NULL 
     OR 
     ( p.id_peoples = @id  
       AND o.id_contacts = p.id 
       AND o.id_status = k.id
     ))

ORDER BY p.date

@idによって渡されるパラメータはどこにありますか.$this->id.

条件は、渡されたパラメーターがnullでないo.id_contacts = p.id AND o.id_status = k.id場合にのみ適用されます。.$this->id.

于 2012-09-06T07:43:53.780 に答える
0
create a string and execute the string at the last.

decalre @thequery varchar(max);
 set @thequery ='select * from emp'
if (1=1)
begin
set @thequery = @thequery + ' where emp_id =1'
end
else
begin
set @thequery = @thequery + ' where emp_id=0'
 end exec("@thequery ");
于 2012-09-06T08:53:24.010 に答える
0

これを試して:

WHERE  p.id_peoples <> ".$this->id." 
       OR ( o.id_contacts = p.id AND
            o.id_status = k.id AND
            ...
          )
于 2012-09-06T07:48:28.780 に答える