简体   繁体   中英

How to join two tables in MySQL and display results?

I've started to learn PHP & MySQL myself and could not understand the below issue. I have created 2 table shown below,

  • enents => evnt_id, evnt_nm_, date, venue, details
  • participants => p_id, p_nm, organization, contact

I just want to join these two tables in order to make search that has two fields where we can select event and participants and make the search. Please anyone help me first to join the table which is appropriate for this scenario.

Thank you very much.

First add common id for both and get like this i put this code only for example

  • events => id , evnt_id, evnt_nm_, date, venue, details
  • participants => p_id, common_id , p_nm, organization, contact

     SELECT events.id,events.evnt_id, events.evnt_nm_, events.date, events.venue, events.details FROM events INNER JOIN participants ON articipants.common_id=events.id; 

It is for inner join

Joining 'em makes no sense - they're not related.

What does make a lot of sense - is getting into this: http://www.w3schools.com/sql/sql_join.asp

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM