I’m not really sure how to ask this question, but I’ll do my best. I have two tables that look like this…
id | firstname | lastname
---+-----------+---------
1 | JD | Gonzo
2 | Mike | Bryan
etc
The other is like this
id | staffid | business
---+---------+---------
1 | 1 | a
2 | 4 | a
etc
I would like to query the staffid’s of the second table, then get their names from the first table and order the results according to the firstname of the first table. I’m not sure how to go about this, but I have thought about just adding the names to the second table then ordering the query according to the names, but I was hoping that there would be a better method for doing this. Thanks in advance for your help. I’m still kind of new to databasing. By the way, I’m using PHP and MySQL
Assuming staffid is a foreign key,
SELECT table2.staffid, table1.firstname FROM table1 INNER JOIN table2 ON table2.staffid = table1.id ORDER BY firstname