2012-08-01 37 views
0

我有兩個表。一個包含兩個文本字段以及其他字段。另一個表包含一個varchar字段。我想使用LIKE%關鍵字%搜索這三個字段。當我僅搜索文本字段或其工作的varchar字段。當我嘗試搜索全部三個時,只有正在搜索的varchar。這裏是SQLmysql像textfield和varchar varchar只返回

SELECT * 
     FROM modx_expertise e 
     INNER JOIN modx_expertise_appraiser ea ON e.expertise_id = ea.expertise_id 
     INNER JOIN modx_web_user_attributes ua ON ua.internalKey = ea.internalKey 
     INNER JOIN modx_web_user_attributes_extended uae ON uae.internalKey = ua.internalkey 
     WHERE uae.specialities 
     OR uae.bio 
     OR e.expertise 
     LIKE '%$keyword%' 
     GROUP BY fname, lname"; 
+0

基本上加上'like'關鍵字爲每一列,貼我的回答如下 – reggie 2012-08-01 20:02:23

回答

0
SELECT * 
     FROM modx_expertise e 
     INNER JOIN modx_expertise_appraiser ea ON e.expertise_id = ea.expertise_id 
     INNER JOIN modx_web_user_attributes ua ON ua.internalKey = ea.internalKey 
     INNER JOIN modx_web_user_attributes_extended uae ON uae.internalKey = ua.internalkey 
     WHERE uae.specialities 
     LIKE '%$keyword%' 
     OR uae.bio 
     LIKE '%$keyword%' 
     OR e.expertise 
     LIKE '%$keyword%' 
     GROUP BY fname, lname"; 
0
... 
WHERE uae.specialities LIKE '%$keyword%' 
OR uae.bio LIKE '%$keyword%' 
OR e.expertise LIKE '%$keyword%' 
...