Groups | Blog | Home
all groups > sql server (alternate) > march 2004 >

sql server (alternate) : relationship issue.


vncntj NO[at]SPAM hotmail.com
3/31/2004 4:36:06 AM
i have three tables
BOOKING
bookId int uniqueidentifier
bookOp varchar(255)

BOOKING_DETAILS
bookid int
z_id nvarchar(255)
detail nvarchar(255)

BOOKING_STAFF
bookId int
staff nvarchar(255)
z_id_row.

I can create the relationship between
BOOKING.bookId = BOOKING_DETAILS.bookid
AND BOOKING.bookId = BOOKING_STAFF.bookid

But instead of getting results like
booking.bookOP booking_details.detail booking_staff.staff
JOHN DOE CAFETERIA JAMES WOOD
JANE DOE LIBRARY DORTHY HARRIS


I'm getting
booking.bookOP booking_details.detail booking_staff.staff
JOHN DOE CAFETERIA JAMES WOOD
JANE DOE LIBRARY DORTHY HARRIS
JOHN DOE CAFETERIA DORTHY HARRIS
JANE DOE LIBRARY JAMES WOOD

But in BOOKING_STAFF there is a BOOKING.z_id_row
and in BOOKING_DETAILS.detail there is BOOKING_DETAILS.z_id

BOOKING.z_id_row booking_details.z_id booking_staff.staff
1 789:12 JAMES WOOD
2 789:13 DORTHY HARRIS

This DOS program apparently uses the BOOKING.z_id_row and
David Portas
3/31/2004 2:43:58 PM
[quoted text, click to view]

A relationship doesn't define the result of a query, you do that with JOINS
in a SELECT statement. It looks like this is the query you are looking for:

SELECT B.bookop, D.detail, S.staff
FROM Booking AS B
JOIN Booking_Details AS D
ON B.bookid = D.bookid
JOIN Booking_Staff AS S
ON D.bookid = S.bookid
AND D.z_id = S.z_id_row

--
David Portas
SQL Server MVP
--

AddThis Social Bookmark Button