[英]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 |
I've been trying inner join to try match the names to id but been unsuccessful 我一直在尝试内部联接以尝试将名称与ID匹配,但未成功
select event_id as id from event_choices inner join restaurants on res_id.id = res_name
any help would be greatly appreciated, very new to php/mysql 任何帮助将不胜感激,这是php / mysql的新手
Try: 尝试:
SELECT event_id, res_name FROM event_choices, restaurants WHERE event_choices.res_id = restaurants.res_id
Enjoy ^_^ 享受^ _ ^
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
could work. 可以工作。
If you select *
instead of event.event_name
you should get all data and be able to pick from it. 如果选择
*
而不是event.event_name
,则应该获取所有数据并能够从中进行选择。 You can also select specific fields in the form of <table>.<field>
. 您还可以选择
<table>.<field>
形式的特定字段。
EDIT: added res_name
编辑:添加
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.