mysql join (many to one)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dbecker88
Forum Newbie
Posts: 1
Joined: Wed Nov 16, 2011 12:35 pm

mysql join (many to one)

Post by dbecker88 »

i have 2 tables in mysql.

TableA - unique records
TableB - many records join to each record in tableA

TableB joins to TableA via 'sub_key'

Code: Select all

$query = "SELECT TableB.Long_Name, TableA.AbbrevName "."FROM TableB, TableA "."WHERE TableA.FACID = '$real_facid' AND TableA.sub_key = TableB.sub_key";
When printing results, how to I list:

TableA.AbbrevName (record1)
-----TableB.Long_Name (joined record1)
-----TableB.Long_Name (joined record2)
-----TableB.Long_Name (joined record3)
TableA.AbbrevName (record2)
-----TableB.Long_Name (joined record1)
-----TableB.Long_Name (joined record2)
TableA.AbbrevName (record3)
-----TableB.Long_Name (joined record1)

thanks!
Post Reply