[英]How can match ids to names from different tables in mysql?
A. event_choices
event_id | res_id |
4 | 10 |
B. restaurants
res_id | res_name |
10 | xyz |
C. event
event_id | event_name |
4 | birthday |
我一直在嘗試內部聯接以嘗試將名稱與ID匹配,但未成功
select event_id as id from event_choices inner join restaurants on res_id.id = res_name
任何幫助將不勝感激,這是php / mysql的新手
嘗試:
SELECT event_id, res_name FROM event_choices, restaurants WHERE event_choices.res_id = restaurants.res_id
享受^ _ ^
SELECT event.event_name, restaurants.res_name FROM event_choices
INNER JOIN restaurants ON event_choices.res_id = restaurants.res_id
INNER JOIN event ON event_choices.event_id = event.event_id
可以工作。
如果選擇*
而不是event.event_name
,則應該獲取所有數據並能夠從中進行選擇。 您還可以選擇<table>.<field>
形式的特定字段。
編輯:添加res_name
嘗試這個:
select ec.event_id as id from event_choices ec inner join restaurants r on ec.res_id = r.res_id
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.