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!

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 :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.