Is there a way that I can select information from multiple rows in a table for another table?
Is there a way that I can select information from multiple rows in a table for another table?
Hi community,
I have two tables and they have the information as follows:
table A (people):
- id
- name
- phone
table B (rooms):
- id
- room name
- person ID 1 (people.id)
- person ID 2 (people.id)
I would like to show the id, name and phone for both people in datatable for table B and also allow users to choose people in Editor via a dropdown list. I first tried to left join table B with table A twice with rooms.person ID 1 = people.id and rooms.personID 2 = people.id but it gave me an error message. Is there a way to do this?
This question has an accepted answers - jump to answer
Answers
A
leftJoin
with an alias would be the way to do it - something like (I'm assuming PHP, but our .NET and Node.js libs would support the same thing with their own syntax):You'd probably want to add
Options
and stuff to the fields, but that's the basic idea.Allan
Thanks, Allan, indeed I am using PHP and that solves the issue.