mysql - SELECT 多個資料表及多個欄位
問題描述
我有個資料表叫做users_workexp 每位使用者能夠新增多筆上去 所以這個資料表若用戶有5筆紀錄 則id欄位會出現(xiàn)5個1 沒錯吧? 可多個而users_profile和users資料表的欄位id 每個用戶都會只有一個
SELECT * FROM `users_profile` JOIN `users` USING (id) JOIN `users_workexp` USING (id) WHERE `users_profile`.`username` LIKE ’%{$key}%’ OR `users_profile`.`name` LIKE ’%{$key}%’ OR `users_profile`.`city` LIKE ’%{$key}%’ OR `users_workexp`.`work_name` LIKE ’%{$key}%’ OR `users_workexp`.`work_bio` LIKE ’%{$key}%’ OR `users`.`email` LIKE ’%{$key}%’ ');
輸出的結(jié)果我是印出 users_profile 的name欄位假設A用戶新增5筆資料到users_workexp搜尋後假設有符合$key的 他會印出'5個'A用戶的name但我希望的是 假設id是一樣的 則只要出現(xiàn)'1個'就可以了
問題解答
回答1:1 對 11 對 多多 對 多
left joinright joininner joinouter join
http://zhidao.baidu.com/quest...
回答2:請再詳細描述下你的幾個表的結(jié)構(gòu),有哪些字段,哪些主鍵和外鍵等,近可能詳細吧,還有你想要實現(xiàn)的查詢時什么?才好對癥下藥
相關(guān)文章:
1. boot2docker無法啟動2. docker-compose中volumes的問題3. docker安裝后出現(xiàn)Cannot connect to the Docker daemon.4. 關(guān)于docker下的nginx壓力測試5. node.js - antdesign怎么集合react-redux對input控件進行初始化賦值6. java - SSH框架中寫分頁時service層中不能注入分頁類7. 老師,按tab鍵不起作用怎么回事8. dockerfile - 為什么docker容器啟動不了?9. mac里的docker如何命令行開啟呢?10. 關(guān)docker hub上有些鏡像的tag被標記““This image has vulnerabilities””

網(wǎng)公網(wǎng)安備