Skip to content
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

Select in other select #1081

Open
OldMen opened this issue Sep 10, 2022 · 13 comments · Fixed by #1124
Open

Select in other select #1081

OldMen opened this issue Sep 10, 2022 · 13 comments · Fixed by #1124
Labels

Comments

@OldMen
Copy link

OldMen commented Sep 10, 2022

Please tell me how to execute the following query:

select * 
from (
    select *
    from table 
    group by name having max(age)) 
where name = 'Bob';
@fnc12
Copy link
Owner

fnc12 commented Sep 10, 2022

hi. Select inside FROM isn't implemented right now. We are thinking about API. If you have any idea you're welcome

@OldMen
Copy link
Author

OldMen commented Sep 10, 2022

storage.select( asterisk(), from( select( ... ) ) );
?

@fnc12
Copy link
Owner

fnc12 commented Sep 10, 2022

@OldMen ok how to specify where name = 'Bob' where name is a column defined inside sub-select?

@OldMen
Copy link
Author

OldMen commented Sep 10, 2022

storage.select( asterisk(), from( select( ... ) ), where( ... ) );

@fnc12
Copy link
Owner

fnc12 commented Sep 10, 2022

please expand ...

@OldMen
Copy link
Author

OldMen commented Sep 10, 2022

storage.select( 
  asterisk<Table>(),
  from( select( asterisk<Table>(), group_by( &Table::name ).having( max( &Table::age ) ) ) ),
  where( is_equal( &Table::name, "Bob ) )
);

@fnc12
Copy link
Owner

fnc12 commented Sep 10, 2022

ok it looks nice thanks. What if we need to use aliases inside sub-select and reference to it in the outer WHERE?

@OldMen
Copy link
Author

OldMen commented Sep 10, 2022

Я не часто использую алиасы, поэтому не могу сразу рассмотреть проблему. :)

@fnc12
Copy link
Owner

fnc12 commented Sep 10, 2022

I can add a support for query provided by you no problem but what to do with queries like this

SELECT departments.department_name, subquery1.latest_hire
FROM departments,
 (SELECT department_id, MAX(hire_date) AS latest_hire
  FROM employees
  GROUP BY department_id) subquery1
WHERE subquery1.department_id = departments.department_id;

?

@OldMen
Copy link
Author

OldMen commented Oct 8, 2022

А если попробовать такой интерфейс?

auto subquery1 = storage.subquery( select( asterisk<Table>(), group_by( &Table::name ).having( max( &Table::age ) ) ) );
auto result = storage.select( subquery1.field, from( subquery1 ) );

@fnc12
Copy link
Owner

fnc12 commented Oct 8, 2022

@OldMen how to specify WHERE subquery1.department_id = departments.department_id; in your case?

@fnc12
Copy link
Owner

fnc12 commented Oct 14, 2022

@OldMen I like Russian language, I speak it mostly and it is my mother language but please write public issues in English cause open source has to be written in English. If you want to speak Russian let's use email fnc12@me.com instead. Thanks

@fnc12
Copy link
Owner

fnc12 commented Nov 2, 2022

@OldMen are you there?

@fnc12 fnc12 added the question label Nov 2, 2022
@trueqbit trueqbit linked a pull request Feb 14, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants