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

[6.0] Refactor UNION queries #29496

Merged
merged 1 commit into from
Aug 11, 2019
Merged

[6.0] Refactor UNION queries #29496

merged 1 commit into from
Aug 11, 2019

Conversation

staudenmeir
Copy link
Contributor

SQL Server is the only database left where we don't wrap the subqueries of UNION queries in parentheses. We can make it the default behavior and remove a lot of duplicate code.

This allows more complex queries on SQL Server:

DB::table('posts')->latest()->limit(5)->unionAll(
    DB::table('videos')->latest()->limit(5)
)->latest()->get();
select * from (
  select top 5 * from [posts] order by [created_at] desc
) as [temp_table]
union all
select * from (
  select top 5 * from [videos] order by [created_at] desc
) as [temp_table]
order by [created_at] desc

The new wrapUnion() method handles the different ways we wrap the subqueries:
(...) vs. select * from (...)

@taylorotwell taylorotwell merged commit 95e1846 into laravel:master Aug 11, 2019
@staudenmeir staudenmeir deleted the union branch August 11, 2019 14:33
yajra added a commit to yajra/laravel-oci8 that referenced this pull request Sep 4, 2019
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 this pull request may close these issues.

2 participants