亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

mysql join問題

mysql join問題

梵蒂岡之花 2018-12-18 22:05:41
有兩張表user表字段:id,username,namearticle表字段:id,art_title,art_content,posterId,controllerIdarticle表中的posterId是外鍵,指向user表中的idarticle表中的controllerId也是外鍵,也指向user表中的id比如現在article中有一條數據:art_id | art_title | art_content | posterId | controllerId1      | title     | content     | 1        | 2user表中有兩條數據user_id | username | name1       | leo      | 小紅2       | john     | 小明我現在要查尋article中的這條數據,但我希望通過posterId和controllerId將poster和controller的信息都查尋出來,請問sql語句該怎么寫啊?我現在的查尋語句是這樣的:SELECT article.*,user.*FROM articleLEFT JOIN userON article.id = user.idWHERE art_id = 1查尋出來的結果是:art_id=>1,art_title=>title,art_content=>content,posterId=>1,controllerId=>2,//我現在想在上面的sql語句中根據controllerId把controller的信息也查尋出來,請問該怎么寫sql語句user_id=>1,    //這是根據posterId得到的poster的信息username=>leo, //這是根據posterId得到的poster的信息name=>小紅     //這是根據posterId得到的poster的信息
查看完整描述

1 回答

?
猛跑小豬

TA貢獻1858條經驗 獲得超8個贊

可以再連接一下

SELECT a.*, b.username,b.name,c.username,c.nameFROM article aLEFT JOIN user bON a.posterId = b.idLEFT JOIN user c ON a.controllerId = c.idWHERE art_id = 1


查看完整回答
反對 回復 2018-12-18
  • 1 回答
  • 0 關注
  • 496 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號