我想在我的網站的搜索功能獲取disting行。從多個表
我想允許基於用戶名,城市,學院/學校名稱,employeer搜索。 名稱是強制性的,其他都是可選字段。 我有以下各表
users(id,fname,lname,city)
profile_pic(id,pic,userid)//userid from users(id)
educationdetail(eduid,school,userid)//userid from users(id)
employment(empid.employeer,userid)//userid from users(id)
在每個用戶profile_pic是僅具有一個圖像; 在educationdetail用戶可以在就業用戶添加多個學校大學細節 可以添加多個工作細節
搜索目的,我使用下面的查詢:
SELECT distinct s.id, s.fname, s.lname,pr.pic
FROM users as s LEFT JOIN profile_pic as pr
on s.id = pr.userid
LEFT JOIN educationdetail as edu
on s.id=edu.userid
LEFT JOIN employment as emp
on s.id=emp.userid
where s.fname like '%m%' and s.lname like '%%%' and s.city like '%%%'
即給予適當的細節
但是當包括很少的參數,它沒有顯示任何結果
SELECT distinct s.id, s.fname, s.lname,pr.pic
FROM users as s LEFT JOIN profile_pic as pr
on s.id = pr.userid
LEFT JOIN educationdetail as edu
on s.id=edu.userid
LEFT JOIN employment as emp
on s.id=emp.userid
where s.fname like '%m%' and s.lname like '%%%' and s.city like '%%%'
and edu.school='%%%' and emp.employeer='%%%';
顯示
Empty set (0.00 sec)
你說的'LIKE '%%%''是什麼意思? –
'%pattern%'此處'%%%'表示任何模式 – xrcwrn