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
 SELECT Statement

Author  Topic 

Reez
Starting Member

3 Posts

Posted - 2008-11-12 : 02:20:06
Hey,

Iam using access but writing the codes through tthe SQL view.
I have 2 tables one: Antenna(AntID,AntTypeID) and another table AntennaType(AntTypeID,AntTypeName)
In the Relations Section Iconnected AntTypeID both together. I want to create a query to display (AntID,AntTypeName)
what's the SELECT statement I should use?
I tried this but it didn't work:
SELECT Antenna.AntID,AntennaType.AntTypeName
FROM Antenna, AntennaType

thank you

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-11-12 : 02:21:46
do you need access query or sql query?
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-11-12 : 02:27:26
You have to relate the to tables.

SELECT *
FROM Antenna AS a
INNER JOIN AntennaType AS t ON t.AntTypeID = a.AntTypeID



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

Reez
Starting Member

3 Posts

Posted - 2008-11-12 : 02:36:02
I want an access query.

I tried this code
SELECT AntID, AntTypeName
FROM AntType INNER JOIN Antenna ON AntennaTypeSpecs.AntTypeID = Antenna.AntTypeID;

It worked, but the query showed me the AntID 1,2,3,4,7 and skipped 5, 6. Why?
Go to Top of Page

lionofdezert
Aged Yak Warrior

885 Posts

Posted - 2008-11-12 : 03:05:41
Do you have data in AntType Table against AntID 5 and 6 (AntTypeId in Anteena table against AntId 5 and 6 should be present in AntType table). Inner join will return only results that qualify the join condition.
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-11-12 : 03:18:09
SELECT *
FROM AntennaType AS t
LEFT JOIN Antenna AS a ON a.AntTypeID = t.AntTypeID


E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

Reez
Starting Member

3 Posts

Posted - 2008-11-12 : 03:37:10
Yes, the data is properly filled and there are no Null fields, I don't know why, and by the way, I created another query, and the next time, the number 3 didn't appear, and I hadn't changed anything.weird.
Go to Top of Page

Nageswar9
Aged Yak Warrior

600 Posts

Posted - 2008-11-17 : 06:25:04
SELECT AntID,AntTypeName
FROM Antenna AS a
INNER JOIN AntennaType AS at (at.AntTypeID = a.AntTypeID)

I Struggle For Excellence
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-11-17 : 07:22:34
quote:
Originally posted by Nageswar9

SELECT AntID,AntTypeName
FROM Antenna AS a
INNER JOIN AntennaType AS at (at.AntTypeID = a.AntTypeID)

I Struggle For Excellence


This is Peso's first reply

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-11-17 : 09:35:17
quote:
Originally posted by madhivanan

quote:
Originally posted by Nageswar9

SELECT AntID,AntTypeName
FROM Antenna AS a
INNER JOIN AntennaType AS at (at.AntTypeID = a.AntTypeID)

I Struggle For Excellence


This is Peso's first reply

Madhivanan

Failing to plan is Planning to fail


seems like he's not at all reading earlier posts before replying
Go to Top of Page
   

- Advertisement -