Subject | Re: [IBO] sql problem |
---|---|
Author | Svein Erling Tysvær |
Post date | 2001-04-26T07:12:19Z |
Steve,
SELECT ITEMUSED_ID
, JOBNO
, ITEMNO
, QTY
, (SELECT CAT1NO FROM ITEMS WHERE ITEMS.ITEMNO=:ITEMNO)
AS CAT1NUM
, (SELECT CAT1 FROM CATEGORY1 WHERE CATEGORY1.CAT1NO=:CAT1NUM)
AS CAT1
FROM ITEMSUSED
isn't quite the same as
SELECT ITEMUSED_ID
, JOBNO
, ITEMNO
, QTY
, CAT1
FROM ITEMSUSED
JOIN CATEGORY1 C1 ON C1.CAT1NO=(SELECT CAT1NO FROM ITEMS WHERE
ITEMS.ITEMNO=ITEMSUSED.ITEMNO)
The first selects records which doesn't necessarily have items in items and
category1, whereas the latter only selects items that exists in these two
tables. If all itemsused can be linked to category1 and items, I suggest
you try to change your SQL to
SELECT IU.ITEMUSED_ID
, IU.JOBNO
, IU.ITEMNO
, IU.QTY
, C1.CAT1
FROM ITEMSUSED IU
JOIN ITEMS I ON I.ITEMNO=IU.ITEMNO
JOIN CATEGORY1 C1 ON C1.CAT1NO=I.CAT1NO
Simpler to read and doesn't mix SQL89 and SQL92 (which isn't recommended -
well, I've never actually seen a select within a join clause before, but I
think your where clause can be described as SQL89).
HTH,
Set
SELECT ITEMUSED_ID
, JOBNO
, ITEMNO
, QTY
, (SELECT CAT1NO FROM ITEMS WHERE ITEMS.ITEMNO=:ITEMNO)
AS CAT1NUM
, (SELECT CAT1 FROM CATEGORY1 WHERE CATEGORY1.CAT1NO=:CAT1NUM)
AS CAT1
FROM ITEMSUSED
isn't quite the same as
SELECT ITEMUSED_ID
, JOBNO
, ITEMNO
, QTY
, CAT1
FROM ITEMSUSED
JOIN CATEGORY1 C1 ON C1.CAT1NO=(SELECT CAT1NO FROM ITEMS WHERE
ITEMS.ITEMNO=ITEMSUSED.ITEMNO)
The first selects records which doesn't necessarily have items in items and
category1, whereas the latter only selects items that exists in these two
tables. If all itemsused can be linked to category1 and items, I suggest
you try to change your SQL to
SELECT IU.ITEMUSED_ID
, IU.JOBNO
, IU.ITEMNO
, IU.QTY
, C1.CAT1
FROM ITEMSUSED IU
JOIN ITEMS I ON I.ITEMNO=IU.ITEMNO
JOIN CATEGORY1 C1 ON C1.CAT1NO=I.CAT1NO
Simpler to read and doesn't mix SQL89 and SQL92 (which isn't recommended -
well, I've never actually seen a select within a join clause before, but I
think your where clause can be described as SQL89).
HTH,
Set