Reputation: 18617
I have a table in a MySQL table called persons
id LastName FirstName 1 Hansen Timoteivn 2 Svendson Tove 3 Pettersen Kari
and another MySQL table called orders.
id OrderNo personID 1 77895 3 2 44678 3 3 22456 1 4 24562 1 5 34764 15
How can I write a SQL query that I feed into PHP's mysql_query()
function to return a list of "Order objects" that each contain a "Person object?" Each "Person object" has first name and last name as properties.
Upvotes: 0
Views: 108
Reputation: 263733
this query will return orders by a certain person (this will not give the object)
SELECT a.ID, a. FirstName, a.LastName, b.OrderNo
FROM Persons a INNER JOIN Orders b ON
a.ID = b.PersonID
WHERE a.ID = 1
Upvotes: 2