Subject | Re: Inner Joins and 3 tables |
---|---|
Author | Alexander V.Nevsky |
Post date | 2004-02-25T17:33:13Z |
--- In firebird-support@yahoogroups.com, JoshCooper@u... wrote:
JOIN conditions, not many times after each to which it is related, so:
SELECT a.ASSY_CODE
FROM MATRIX m
INNER JOIN MATRIX_CELL_ASSY mca
ON m.MATRIX_ID = mca.MATRIX_ID
INNER JOIN ASSEMBLY a
ON mca.ASSY_ID = a.ASSY_ID WHERE a.ASSY_LIB_ID = mca.ASSY_LIB_ID
WHERE MATRIX_LIB_ID = 3 And MATRIX_ID = 87
Though you can avoid usage of WHERE at all and apply it's condition
directly in JOIN, like
SELECT a.ASSY_CODE
FROM MATRIX m
INNER JOIN MATRIX_CELL_ASSY mca
ON m.MATRIX_ID = mca.MATRIX_ID
And MATRIX_LIB_ID = 3 And MATRIX_ID = 87
INNER JOIN ASSEMBLY a
ON mca.ASSY_ID = a.ASSY_ID WHERE a.ASSY_LIB_ID = mca.ASSY_LIB_ID
Can't surely say what is better, both will work.
Best regards,
Alexander.
>statement:
> Do firebird (1.5stable) support subqueries? I have the following
>= 87
> SELECT a.ASSY_CODE FROM MATRIX m
> INNER JOIN MATRIX_CELL_ASSY mca
> ON m.MATRIX_ID = mca.MATRIX_ID WHERE MATRIX_LIB_ID = 3 And MATRIX_ID
> INNER JOIN ASSEMBLY aget an
> ON mca.ASSY_ID = a.ASSY_ID WHERE a.ASSY_LIB_ID = mca.ASSY_LIB_ID
>
> which appears to be correct, eachy INNER JOIN works on its on, but I
> error when i get to the second inner join.done
> Is it a syntax issue (grouping of some sort) or can this just not be
> currently?Josh, pay more attention to TFM ;) WHERE should be written after ALL
JOIN conditions, not many times after each to which it is related, so:
SELECT a.ASSY_CODE
FROM MATRIX m
INNER JOIN MATRIX_CELL_ASSY mca
ON m.MATRIX_ID = mca.MATRIX_ID
INNER JOIN ASSEMBLY a
ON mca.ASSY_ID = a.ASSY_ID WHERE a.ASSY_LIB_ID = mca.ASSY_LIB_ID
WHERE MATRIX_LIB_ID = 3 And MATRIX_ID = 87
Though you can avoid usage of WHERE at all and apply it's condition
directly in JOIN, like
SELECT a.ASSY_CODE
FROM MATRIX m
INNER JOIN MATRIX_CELL_ASSY mca
ON m.MATRIX_ID = mca.MATRIX_ID
And MATRIX_LIB_ID = 3 And MATRIX_ID = 87
INNER JOIN ASSEMBLY a
ON mca.ASSY_ID = a.ASSY_ID WHERE a.ASSY_LIB_ID = mca.ASSY_LIB_ID
Can't surely say what is better, both will work.
Best regards,
Alexander.