Trying to create a multiple table query

alphadawg

New member
Local time
Today, 08:47
Joined
Dec 18, 2012
Messages
7
I have the tables tbl_staff and tbl_trip.

I want a select query which lists staff members and shows all the trips they have managed (been group leader of.)

In the trip table, the group leader is stored in Group_Leader_ID, which corresponds with Staff_ID. The fields I want to be output is the staff name from the staff table and the trip title from the trip table.

I thought I had the knowledge to write the SQL statement for this but got confused now that i'm bringing in more than one table. If anyone could guide me in the right direction, that would be great.
 
how about this

SELECT tbl_Staff.Staff_Name, tbl_Trip.Trip_Title
FROM tbl_Staff RIGHT JOIN tbl_Trip ON tbl_Staff.Staff_ID = tbl_Trip.Trip_Leader;
 
That worked! thankyou! I think I understand the code a bit better now too :)
 
Don't know if this help, I am still learning myself, but when I am trying to write a SQL query, I usually just build a query in Design View in Access, make sure it works and then view the query in SQL View and copy that into a view in my SQL. As long as there aren't too many expressions in the query it usually works for me. Here is what I got from your info:

SELECT tbl_staff.Staff_ID, tbl_staff.StaffName, tbl_trip.TripName
FROM tbl_staff INNER JOIN tbl_trip ON tbl_staff.Staff_ID = tbl_trip.Group_Leader_ID
ORDER BY tbl_staff.Staff_ID, tbl_staff.StaffName, tbl_trip.TripName;
 

Users who are viewing this thread

Back
Top Bottom