question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

MySQL UNION with query builder possible?

See original GitHub issue

Issue type:

[x] question [ ] bug report [x] feature request [x] documentation issue

Database system/driver:

[ ] cordova [ ] mongodb [ ] mssql [x] mysql / mariadb [ ] oracle [ ] postgres [ ] sqlite [ ] sqljs [ ] react-native [ ] expo

TypeORM version:

[x] latest [ ] @next [ ] 0.x.x (or put your version here)

Steps to reproduce or a small repository showing the problem: Is it possible to create a UNION select statement using the query builder? I can’t find anything in the documentation about that.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:8
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

169reactions
lffgcommented, Nov 19, 2020

@pleerock, are there any plans to add union to the query builder API?

35reactions
golubvladimircommented, Jul 9, 2021

My version

    const entityManager = getManager();

    const tableUn = this.tableUnion.createQueryBuilder('tu')
        .select(['id', 'description'])
        .getQuery();

    const tableTg = this.tags.createQueryBuilder('tg')
        .select(['id', 'name'])
        .getQuery();

    const tags = await entityManager.query(`${ tableUn } UNION ${ tableTg }`);

    return tags;
  }
Read more comments on GitHub >

github_iconTop Results From Across the Web

Union queries from different databases in Laravel Query Builder
I have two similar tables in two different databases. Both tables have a column with a date and one with email addresses. Though...
Read more >
Working with unions in Active Query Builder - User's Guide
Union sub-queries can be grouped with other sub-queries and joined with different operators (UNION, UNION ALL, EXCEPT, INTERSECT). To add a new union...
Read more >
Example of unionAll in Query Builder Laravel
If you use union all then laravel query builder provide unionAll method for mysql union. when you are doing big project or ERP...
Read more >
Add union() to DB Query Builder - CodeIgniter Forums
This is what I do on very complex queries (or dynamic queries). And it works fine with the UNION command as I've used...
Read more >
can't use where clause after union of 2 queries - Laracasts
That is down to MYSQL rather than Laravel. As you can see from the example here, if you want to do a where...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found