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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with SQL Statement

Status
Not open for further replies.

tsyle

Programmer
May 16, 2005
35
US
Hi I am having problems trying to get two tables to show reference each other correctly.

Here is the problem:

What are the Lab_Test_Result for Visit with number less than 7? Include the Visit_Number, Lab_Order_Number, Result_Code Result_Reading, and the Result Units.

This is what I got, but its giving me too many outputs.

SELECT Visit_Number, Lab_Order_Number, Result_Code, Result_Reading, Result_Units
FROM Lab_Test_Result, Visit
WHERE Visit_Number < 7
ORDER By Result_Code, Visit_Number;

Gave me like 400 answers.
 
You didn't specify how the 2 tables are joined. There should be a field in both tables that link the records together. So, your query should look something like...

Code:
SELECT Visit_Number, Lab_Order_Number, Result_Code, Result_Reading, Result_Units
FROM Lab_Test_Result inner join Visit on Lab_TestResult.SomeField = Visit.SomeField
WHERE Visit_Number < 7
ORDER By Result_Code, Visit_Number

Of course, I don't really know how the 2 tables are related, but this should give you a start.

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top