搜尋

首頁  >  問答  >  主體

php - MySQL二表查詢某字段相同的記錄並輸出某字段


user表


single表

如圖 怎麼查詢user與single表中user相同的記錄 且輸出user表的id user single表的exam_name欄位

或說這個表怎麼改更好點

還有一個問題

如果要修改user表中的user的話 single表所對應的user怎麼同時被修改?新手 不是很懂 希望朋友們幫忙 教我 謝謝

phpcn_u1582phpcn_u15822787 天前785

全部回覆(3)我來回復

  • phpcn_u1582

    phpcn_u15822017-06-23 09:13:33

    從使用者中選擇a.id,a.user,b.exam_namc作為連接單作為b on a.user = b.user

    回覆
    0
  • 过去多啦不再A梦

    过去多啦不再A梦2017-06-23 09:13:33

    沒有調試
    1、

    select u.id, u.user, s.exam_name from user u, single s where u.user = s.user

    2、

    update user u,single s  set u.user = '值', s.user = '值' where u.user = u.user and u.id = '条件'

    回覆
    0
  • 某草草

    某草草2017-06-23 09:13:33

    Select 的時候把兩個表join 起來,你可以查一下sql join 的用法。

    回覆
    0
  • 取消回覆