Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Post History
Lets say I have two tables, A and B and I need to join a subset of them. Is there best practices of sticking the conditions in the WHERE clause like this, SELECT * FROM A JOIN B on a.fk_b = b....
#4: Post edited
- Lets say I have two tables, A and B and I need to join a subset of them.
- Is there best practices of sticking the conditions in the WHERE clause like this,
```- SELECT *
- FROM A
- JOIN B on a.fk_b = b.pk
- WHERE a.pk <10000
- ```
- versus sticking the condition in the JOIN like this,
```- SELECT *
- FROM A
- JOIN B on a.fk_b = b.pk
- AND a.pk <10000
- ```
- For these, it doesn't make any difference in speed or results, but are there best practices for where to put the conditions?
- Lets say I have two tables, A and B and I need to join a subset of them.
- Is there best practices of sticking the conditions in the WHERE clause like this,
- ```sql
- SELECT *
- FROM A
- JOIN B on a.fk_b = b.pk
- WHERE a.pk <10000
- ```
- versus sticking the condition in the JOIN like this,
- ```sql
- SELECT *
- FROM A
- JOIN B on a.fk_b = b.pk
- AND a.pk <10000
- ```
- For these, it doesn't make any difference in speed or results, but are there best practices for where to put the conditions?
#3: Post edited
- Lets say I have two tables, A and B and I need to join a subset of them.
- Is there best practices of sticking the conditions in the WHERE clause like this,
- ```
- SELECT *
- FROM A
- JOIN B on a.fk_b = b.pk
- WHERE a.pk <10000
- ```
- versus sticking the condition in the JOIN like this,
- ```
- SELECT *
- FROM A
- JOIN B on a.fk_b = b.pk
- AND a.pk <10000
- ```
For these, it doesn't make any difference in speed or results, but are there best practices for where to put the conditions?
- Lets say I have two tables, A and B and I need to join a subset of them.
- Is there best practices of sticking the conditions in the WHERE clause like this,
- ```
- SELECT *
- FROM A
- JOIN B on a.fk_b = b.pk
- WHERE a.pk <10000
- ```
- versus sticking the condition in the JOIN like this,
- ```
- SELECT *
- FROM A
- JOIN B on a.fk_b = b.pk
- AND a.pk <10000
- ```
- For these, it doesn't make any difference in speed or results, but are there best practices for where to put the conditions?
#1: Initial revision
Are there best practices for sticking conditions in WHERE clauses vs JOIN conditions
Lets say I have two tables, A and B and I need to join a subset of them. Is there best practices of sticking the conditions in the WHERE clause like this, ``` SELECT * FROM A JOIN B on a.fk_b = b.pk WHERE a.pk <10000 ``` versus sticking the condition in the JOIN like this, ``` SELECT * FROM A JOIN B on a.fk_b = b.pk AND a.pk <10000 ``` For these, it doesn't make any difference in speed or results, but are there best practices for where to put the conditions?