Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 3 Table Query Help Needed

Author  Topic 

StealthRider
Starting Member

13 Posts

Posted - 2009-05-21 : 11:59:15
I have created 3 tables:

Fruit, Price, Grows

Fruit:
Item
Color

Price:
Item
Cost

Grows:
Item
Location

The Query should result in:

Items thats Red, That Cost 4.00, That Grows in SC

This is my code:

SELECT Item
FROM Fruit, Price, Grows
WHERE Color = Red, Cost = 4.00, Location = SC

Error:

Msg 102, Level 15, State 1, Line 3
Incorrect syntax near ','.

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2009-05-21 : 12:35:45
You should use joins not FROM Fruit, Price, Grows
and in your where clause, replace the ','s with 'and'
WHERE Color = Red and Cost = 4.00 and Location = SC

Jim
Go to Top of Page

StealthRider
Starting Member

13 Posts

Posted - 2009-05-21 : 12:44:28
OK, I tried this:

SELECT Item
join Fruit, Price, Grows
WHERE Color = Red and Cost = 4.00 and Location = SC

Error:

Msg 156, Level 15, State 1, Line 2
Incorrect syntax near the keyword 'join'.
Go to Top of Page

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2009-05-21 : 13:00:50
You could look up the JOIN clause in Books On Line. Or go to W3 schools, they're great places to start learning SQL Server


Jim
Go to Top of Page

StealthRider
Starting Member

13 Posts

Posted - 2009-05-21 : 14:26:42
Thanks, looking over that now, still not really sure how to do this, but I guess it try, try, try, til you get it right. Hhahahahahaha
Go to Top of Page

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2009-05-21 : 15:32:12
Try, try, try and then give us what you got, and get more help as you need it. People are very good here and quite ready to help those willing to help themselves.

Good Luck!

Jim
Go to Top of Page

StealthRider
Starting Member

13 Posts

Posted - 2009-05-21 : 22:40:40
OK, With a lil help I got it to work but I'm not 1005 sure what the code is doing so let me try to explain and someone please correct me if I'm wrong:

SELECT p.Item = <B>Selecting the Price Item</B>
FROM Fruit f = Saying from the Friut which f = fruit
inner join Price p = ????????????
on f.item = p.item = Say Fruit Item = Price Item
inner join Grows g = ????????????
on p.item = g.item = Price Item = Grow Items
WHERE Color = 'Red' AND Cost = '4.00' AND Location = 'SC'= The Information we are pulling out the tables

Can some help me Understand Inner Join

Thanks
Go to Top of Page
   

- Advertisement -