![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Hi, I have several tables linked in various ways so that an inner join is possible. However, at the same time and in the same SQL query, I'd also like to query by some field values in one of the tables. Two quick questions: a)Will MySQL allow joins that involve more than two tables (in my case, perhaps as many as 5)? Yes. The join limit is 128 tables but if you hit it you've just done it |
|
b)Can limits on a key field be included in the join in the same SQL statement as does the join, i.e. ... WHERE N>3 AND N<20 ... or something like that. Yes. Though not everyone considers it good practice. As an example: |
#3
| |||
| |||
|
|
Hi, I have several tables linked in various ways so that an inner join is possible. However, at the same time and in the same SQL query, I'd also like to query by some field values in one of the tables. Two quick questions: a)Will MySQL allow joins that involve more than two tables (in my case, perhaps as many as 5)? b)Can limits on a key field be included in the join in the same SQL statement as does the join, i.e. ... WHERE N>3 AND N<20 ... or something like that. |
#4
| |||
| |||
|
|
"David T. Ashley" <dta (AT) e3ft (DOT) com> wrote on 07/02/2006 14:03:04: a)Will MySQL allow joins that involve more than two tables (in my case, perhaps as many as 5)? b)Can limits on a key field be included in the join in the same SQL statement as does the join, i.e. ... WHERE N>3 AND N<20 ... or something like that. Yes, you can do multi-way joins, and people often do. My biggest is 3-way, but some people do at least 5-way. Beware that it is easy to specify operations which will heavily load the system if you are not careful. The constraints in the WHERE statement are *logically* and syntactically done on the huge table produced by the joins. However, the MySQL optimiser is not stupid and will perform the filter upstream of the JOIN where possible. Some experimentation and use of the EXPLAIN statement may be necessary to find the best ordering for queries. |
#5
| |||
| |||
|
|
Yes, you can do multi-way joins, and people often do. My biggest is 3-way, but some people do at least 5-way. |
|
Beware that it is easy to specify operations which will heavily load the system if you are not careful. |
![]() |
| Thread Tools | |
| Display Modes | |
| |