Skip to content

Support Sub-Queries in Select List? #930

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
luckygc opened this issue Apr 11, 2025 · 2 comments · Fixed by #940
Closed

Support Sub-Queries in Select List? #930

luckygc opened this issue Apr 11, 2025 · 2 comments · Fixed by #940

Comments

@luckygc
Copy link

luckygc commented Apr 11, 2025

if i want to write sql like this,

select id, (select count(*) from sub) as cnt from main where id=?

what should i do?

@jeffgbutler
Copy link
Member

jeffgbutler commented Apr 11, 2025

That query doesn't really make sense. I assume you want to know the number of rows in sub that have the same id as main - not the total rows in sub. But I think I understand the larger question.

We don't support sub-queries in the select list right now, but it should be relatively simple to add it.

In the mean time, it might be helpful to think of this particular query as a join (which it actually is). You could code it like this:

select main.id, count(*) as cnt
from main join sub on main.id = sub.id
group by main.id
where main.id = ?

@luckygc
Copy link
Author

luckygc commented Apr 14, 2025

Sorry, I forgot to mention some conditions. Subqueries are more intuitive to me. Thank you for your reply.

@luckygc luckygc closed this as completed Apr 14, 2025
@jeffgbutler jeffgbutler changed the title question for select column Support Sub-Queries in Select List? May 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants