0

I am trying to create views of a database containing information about horses, more specifically horses, their owners, and the horse boarder. The view must join three tables. I have to create a view of "first name, last name, primary phone, and barnname". Then I have to join tables "boarder, horse, and boarder_horse" to create the relationship. I can't figure out how to connect the various tables together.

So far, this is what I have:

CREATE VIEW horse_owner
AS
SELECT b.boarder firstname, b.boarder lastname, b.boarder primaryphone, 
h.horse barname

FROM boarder b
INNER JOIN horse h
ON bh.horse_id = h.id
INNER JOIN boarder_horse
ON bh.boarder_id = b.id

ORDER BY LastName DESC;

I don't understand how to correctly link the appropriate tables together.

Michał Turczyn
  • 32,028
  • 14
  • 47
  • 69

1 Answers1

0

You had order of JOINs wrong. Also, you were missing alias bh. Try:

CREATE VIEW horse_owner
AS
SELECT b.firstname, b.lastname, b.primaryphone, 
h.barname

FROM boarder b
INNER JOIN boarder_horse bh
ON bh.boarder_id = b.id
INNER JOIN horse h
ON bh.horse_id = h.id

ORDER BY LastName DESC;
Michał Turczyn
  • 32,028
  • 14
  • 47
  • 69