-
February 13th, 2008, 11:23 PM
#1
Sql Command - 2 Inner Joins
Not sure how to do this - keep getting a syntax error
THIS WORKS (One Inner Join)
Code:
Select [ACCOUNT], [KEY], [Stock].[DESC], [GRP], [CLASS], [PRICE], [FROM_DATE], [TO_DATE], [TYPE_CD] from [SpecialPrices] INNER JOIN [Stock] ON [SpecialPrices].[KEY] = [Stock].[Key] ORDER BY [ACCOUNT] ASC
I would like to do 2 Inner Joins so that I can have the Account Name alongside the Account Number
So I presume it will look something like ...
Code:
Select [ACCOUNT], [Debtor].[Account_Name], [KEY], [Stock].[DESC], [GRP], [CLASS], [PRICE], [FROM_DATE], [TO_DATE], [TYPE_CD] from [SpecialPrices] INNER JOIN [Debtor] ON [SpecialPrices].[ACCOUNT] = [Debtor].[DR_KEY] INNER JOIN [Stock] ON [SpecialPrices].[KEY] = [Stock].[Key] ORDER BY [ACCOUNT] ASC
The added code is BOLD but gives a syntax error
-
February 14th, 2008, 10:05 AM
#2
Re: Sql Command - 2 Inner Joins
What is the syntax error? For example, MySQL returns something like, you have an error in your query NEAR 'FROM Assignments'.
Could you have a duplicate field name in the list of fields your a pulling(IE, could there be a filed named [CLASS]/[PRICE]... in the Debtor table)?
-
February 16th, 2008, 02:18 AM
#3
Re: Sql Command - 2 Inner Joins
Try This ,
Code:
Select
`SpecialPrices`.`ACCOUNT`,
`Debtor`.`Account_Name`,
`SpecialPrices`.`KEY`,
`Stock`.`DESC`,
`GRP`,
`CLASS`,
`PRICE`,
`FROM_DATE`,
`TO_DATE`,
`TYPE_CD`
from `SpecialPrices`
INNER JOIN `Debtor` ON
`SpecialPrices`.`ACCOUNT` = `Debtor`.`DR_KEY`
INNER JOIN `Stock` ON
`SpecialPrices`.`KEY` = `Stock`.`Key`
ORDER BY `ACCOUNT` ASC
-
February 17th, 2008, 01:25 AM
#4
Re: Sql Command - 2 Inner Joins
I'd have done it in following way:
Code:
SELECT Account, D.Account_Name, SP.Key, St.Desc, Grp, Class, Price, From_Date, To_Date, Type_CD
FROM SpecialPrices SP, Debtor D, Stock SP
WHERE SP.Account = D.Dr_Key
AND SP.Key = St.Key
ORDER BY Account ASC
The only problem I found in your code : column 'Key' is ambigious. You haven't specified which 'Key' to read as there are two columns with same name in data source.
-
February 20th, 2008, 07:16 AM
#5
Re: Sql Command - 2 Inner Joins
Thanks so much Shaikh - you have achieved 2 Inner Joins without even specifying ONE !
Your code also becomes much easier to follow - Great !
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|