2016-12-02 6 views
-1

私は、test_idというカラムを持つテーブルを持っています。t-0105、t-0120、t-044、t-063、t-064、t-068 、t-072ですが、クエリはすべてのデータを取得しています。間違ったデータを取得しています。

select * from test_name where test_type='p' and test_id NOT IN ('t-0105,t-0120,t-044,t-063,t-064,t-068,t-072') and test_list='tt' and test_name like '%aptitude%' and published=1 order by id asc 
+0

「Not In」の文字列全体を引用符で囲みません – jitendrapurohit

答えて

4

一重引用符'を間違って入力しました。クエリでは、IN条件はすべての値を1つの文字列として受け取ります。以下のように追加する必要があります。

select * from test_name where test_type='p' and test_id NOT IN ('t-0105','t-0120','t-044','t-063','t-064','t-068','t-072') and test_list='tt' and test_name like '%aptitude%' and published=1 order by id asc 
関連する問題