Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL newbie.. I think it's a join issue....

Status
Not open for further replies.

PogoWolf

Programmer
Mar 2, 2001
351
US
Hello all!.. I hope you don't mind me asking a quick SQL question? (well, I
hope it's quick..LOL)
I have two tables:

Que QueLookUp

AutoID | Info AutoID | Owner | Name
1 | Foobar 1 | Matt | 1

Where as the AutoID from Table1.. is a lookup to the Name field in Table2
so if I Was looking at this in Access.. I would see in Table 2.. 1, Matt,
FooBar..

that's great.. the issue is.. in SQL.. it returns the 1 as you see here.. I
need an SQL statment to pull
the record from the Info Field ..where Name = the autoID

Currently I have something like this:

SELECT Que
FROM Que, QueLookUp
WHERE Que.AutoID = QueLookUp.Queue
AND QueLookUp.Owner = 3;

and that's not working.... any ideas?

- [aspsqlhowto] member pogowolf@hotmail.com
- ******
Darkness... Bleakness...
and Plastic forks...
--The PogoWolf
 
You can't put a table name behind the SELECT clause. It expects the names of fields.
Use either * to get all fields from one table, or write the fieldnames separated by comma. Like this:
Code:
SELECT AutoID, Owner, Name, Info
FROM Que, QueLookUp
WHERE Que.AutoID = QueLookUp.Queue
  AND QueLookUp.Owner = 3;

Also check up on the WHERE clause, as QueLookUp.Owner is in your example a string value, and QueLookUp.Queue don't exsist.

Good Luck
-Mats Hulten
 
Select QueLookup.Auto,QueLookup.Owner,Que.Info As Name
FROM Que INNER JOIN QueLookup ON Que.AutoID = QueLookup.AutoID
WHERE QueLookup.Owner = 3

Try that
 
I use Access to create the query that I need. Than copy the sql code into my vb program. Thatway there is no mistake. If you're using sql server, then use Microsoft query. Then copy the code. It'll help you learn the sql language too!

Hope this helps...

-Gary
 
Hey Gary, I ending up checking the code that way.. =)
and ending up with this code that works! =)

SELECT [Companys].[Name]
FROM CompanyLookUp, Companys
WHERE [CompanyLookUp].[Company]=[Companys].[AutoID] And [CompanyLookUp].[Owner]=3; ******
Darkness... Bleakness...
and Plastic forks...
--The PogoWolf
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top