Click here to Skip to main content
14,601,060 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hi -

I am not good with sql at all. That said I'll explain my table structure and problem.

I have a tech station table that holds a tech id and station id.
I have a tech table that holds tech id and email.
I have a station table that hold a station id receiver id and antenna id.

My problem is I need to query my tech station and find all the tech id and in a sub query I query my tech table with a given email

select @records = sum(stationid) from TechStation where TechID = (select TechID from Tech where Email = 'name@company.com')


If the record amount is = 1
I am trying to query my station table based on the station id to get the receiverid and antennaid

select 
	ReceiverID,
	AntennaID 
from Station 
where StationID = (select StationID from TechStation where TechID = (select TechID from Tech where Email = 'name@company.com'))


When I run this I just get the commands completed successfully. How can I get the receiver id antenna id combination or can I use inner joins for this? Because when I get those values I want to pass them to another table to make sure I get a single tag

Something like select receiverid, antennaid from processtag where the receiverid and antannadid are the values I queried for above.

Any help is greatly appreciated.

Thanks

What I have tried:

select @records = sum(stationid) from TechStation where TechID = (select TechID from Tech where Email = 'name@company.com')


If the record amount is = 1
I am trying to query my station table based on the station id to get the receiverid and antennaid

select 
	ReceiverID,
	AntennaID 
from Station 
where StationID = (select StationID from TechStation where TechID = (select TechID from Tech where Email = 'name@company.com'))
Posted
Updated 21-Nov-19 13:03pm
v3

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

First thing which comes to my mind: why are you summing ids? Do they have an arithmetic relation? If you want to count the number of techstation records for a specific tech, the count function may be more appropriate.

As for your question, you may just need to join the tables:
SELECT
  s.ReceiverID
 ,s.AntennaID
FROM
 Station s
INNER JOIN
 TechStation ts ON ts.StationID = s.StationID
INNER JOIN
 Tech t ON t.TechID = ts.TechID
WHERE
 t.Email = 'name@company.com'
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100