I have three tables:
- Table1: Account (UserID, FirstName, LastName)
- Table2: Luncheon (LuncheonID, Restaurant, Date, Address)
- Table3: SignUp (UserID, LuncheonID)
I am trying to populate a GridView with columns:
FirstName, LastName, Restaurant, Date, Address
I have tried several queries and struggled with
exposed names. Use correlation names to distinguish them.
and
The multi-part identifier could not be bound.
The latest query I have tried:
SELECT a.FirstName AS Name, l.Restaurant AS Location, l.Date AS Date
FROM Account AS a, Luncheon AS l, SignUp AS s
JOIN
a ON s.UserID = a.UserID
JOIN
l ON s.UserID = l.LuncheonID;
which resolved those errors, but results in
Error: Invalid object name 'a'.
What is the correct query syntax? Also, I would like to combine FirstName and LastName into a single column and sort by Name or Date.
Answer
perhaps write like this
SELECT a.FirstName AS Name, l.Restaurant AS Location, l.Date AS Date
FROM Account AS a
JOIN SignUp AS s ON s.UserID = a.UserID
JOIN Luncheon AS l ON s.UserID = l.LuncheonID;