Bharti Kumawat
Bharti Kumawat

Reputation: 5

How to join two tables to fetch common values

I am just learning PHP. I have two tables one is table a and other is table b. Fields of table a are: snum, sfirst, smiddle, slast. and Fields of table b are : sr_no, st_id. Here Table a's snum and table b's st_id have common values that is id of student. I want to join both tables and find out sfirst, smiddle, slast according to this id. I want to insert id in database and fetch names sfirst, smiddle, and slast according to st_id of table b. Please guide me how can I solve it in easiest way?

Upvotes: 0

Views: 255

Answers (2)

Oliver M Grech
Oliver M Grech

Reputation: 3171

have a look at the tutorials here

Tutorials Point Mysql

Please note that the above link takes you directly to the joins section :)

PS: Tizag also have some good Tutorials which are worth checking ;)

have a nice day :)

Upvotes: 0

Ian Gregory
Ian Gregory

Reputation: 5820

SELECT sfirst, smiddle, slast 
FROM tablea 
INNER JOIN tableb 
on tablea.snum = tableb.st_id 
WHERE tableb.st_id = 1 

Upvotes: 2

Related Questions