0

I am wondering if it is possible to use result of main select inside subquery. I am giving the below example. It is not very clear query, but the only thing you need to know and I am asking about is how to use table1.id inside subquery. I am getting error "Unknown column 'table1.id' in 'on clause'". Is it even possible to use data from "outer" select inside subquery?

SELECT
(SELECT table2.budget FROM project_objects
INNER JOIN project_objects AS table2 ON table2.project_id=table1.id),
table1.id
FROM project_objects AS ticket
INNER JOIN projects AS table1 ON table1.id=ticket.project_id
GROUP BY table1.id

Thanks a lot!

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by pratik_garg
0

Yes it is allowed to use outer query data inside the inner query also...

i am not sure about joins (and in on clouse) .. according to my view you can use this condition (table2.project_id=table1.id) in where condition

!!! you don't have any join condition here

okay then ---

SELECT
(SELECT table2.budget FROM project_objects 
INNER JOIN project_objects AS table2 
where table2.project_id=table1.id),
table1.id
FROM project_objects AS ticket 
INNER JOIN projects AS table1 
ON table1.id=ticket.project_id 
GROUP BY table1.id

above query should work..and should solve your problem also :)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.