Reputation: 187
SELECT [qt].[name] , [qz].[user_id] , [ft].[name]
FROM [f]
INNER JOIN [o] ON [o].[id] = [f].[o_id]
INNER JOIN [q] as q2 ON [q2].[id] = [o].[q_id]
INNER JOIN [ft] ON [ft].[id] = [f].[ft_id]
INNER JOIN [qt] ON [q].[qt_id] = [qt].[id]
INNER JOIN [qz] ON [q].[id] = [qz].[q_id]
WHERE exportable = 1
This is my query.For some reason I'm getting the "the multi-part identifier could not be bound" error for lines 6 and 7,but I don't actually know why.Giving a hint would be great.
Thanks in advance.
Upvotes: 0
Views: 2978
Reputation: 49270
The alias q2
isn't required. If so, you have to use the alias in the last join
condition.
The problem with the original query was that a table alias defined previously ([q] as q2
) wasn't being used in the later condition.
It is also a good practice to use the tablename before exportable
in the where
clause.
SELECT [qt].[name] , [qz].[user_id] , [ft].[name]
FROM [f]
INNER JOIN [o] ON [o].[id] = [f].[o_id]
INNER JOIN [q] ON [q].[id] = [o].[quelle_id]
INNER JOIN [ft] ON [ft].[id] = [f].[ft_id]
INNER JOIN [qt] ON [q].[qt_id] = [qt].[id]
INNER JOIN [qz] ON [q].[id] = [qz].[q_id]
WHERE exportable = 1
Upvotes: 1
Reputation: 176024
Error in line ON [q].[id] = [qz].[q_id]
You created alias on table q as q2
and you need to refer table using this alias.
SELECT [qt].[name]
,[qz].[user_id]
,[ft].[name]
FROM [f]
JOIN [o]
ON [o].[id] = [f].[o_id]
JOIN [q] as q2 -- alias created, so you need to use it
ON [q2].[id] = [o].[q_id]
JOIN [ft]
ON [ft].[id] = [f].[ft_id]
JOIN [qt]
ON [q].[qt_id] = [qt].[id]
JOIN [qz]
ON [q2].[id] = [qz].[q_id]
WHERE exportable = 1
Upvotes: 1