[Question] How one could implement JOIN with a subquery?
See original GitHub issueFirst of all, thank you for your hard work. The question is, how to write a query like below using Exposed
SELECT *
FROM categories
LEFT JOIN products ON products.id = (
SELECT products.id
FROM products
WHERE products.category_id = categories.id
LIMIT 1
)
LIMIT 10
I’d found related issue but it didn’t help
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Subquery vs. JOIN - LearnSQL.com
Subqueries and JOIN s can both be used in a complex query to select data from multiple tables, but they do so in...
Read more >Subqueries and JOINs - MariaDB Knowledge Base
Rewriting Subqueries as JOINS A subquery using IN can be rewritten with the DISTINCT keyword, for example: SELECT * FROM table1 WHERE col1...
Read more >SQL Join vs Subquery - GeeksforGeeks
What are Joins? A join is a query that combines records from two or more tables. A join will be performed whenever multiple...
Read more >Joins and Subqueries in SQL - Web Age Solutions
An SQL Join statement is used to combine data or rows from two or more tables based on a common field between them....
Read more >Understanding when to use a subquery over a join
They're not the same thing. In the query with joins you can potentially multiply rows or have rows entirely removed from the results....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
There is
eqSubQuery
operator in Exposed, you can use it like:But I think in that case it’s more efficient to not use subquery. afaiu the code below will give same result.
Please provide raw SQL and I’ll try to show how to convert it into Exposed DSL