sql 連線查詢例項(left join)三表連線查詢

TinybicXL發表於2019-07-17

當前有三個表 :

  • CommercialNews as a
  • WebCommunity as b
  • CommercialNewsOriginalWebsite as c

條件是  a.idcommunity = b.webid , a.originalWebid = c.idnumber  

要求從三個表裡查出符合上述條件的 以下欄位,並以 a.creadate 進行desc降序排序: 

  • a.idnumber
  • a.creadate
  • a.description
  • a.fileurl
  • a.title
  • b.wname
  • c.webName
  • c.logo 

最後sql語句為:

select a.idnumber,a.creadate,a.description,a.fileurl,a.title,b.wname,c.webName,c.logo 
from commercialnews as a 
left join webcommunity as b on a.idcommunity = b.webid 
left join CommercialNewsOriginalWebsite as c on a.originalWebid = c.idnumber order by a.creadate desc;

 

相關文章