Wednesday, March 7, 2012

Join statement

Hi.......

Its been awhile since I've touched SQL statements, so I need some help
with writing a JOIN statement to query 3 tables.

The dB has 3 tables with values
Applications
-Application_code(Primary key)
-Application_name

Applications_Installed
-Computer_name(Pri key)
-Application_code(Foreign key/sec key)

Workstation_info
-Computer_name(Pri key)
-Serial_number

What I want to do is query the tables for a particular Application code
and name from Applications, so that it returns the values of computer
names with the matching values from Applications_installed and
Workstation_info.

So I need to do a

Select * from applications where applications.application_code='XXX'
join (this is the part I'm stuck how do I tell it to match the
applications.application_code =
applications_installed.application_code) then match the computer names
from Applications_installed.computer_name with that of
workstation_info.computer_name

Not sure if I'm explaining this properly...

Can anyone help......Hey Zeno,

I think what you're looking for is:

SELECT columnlist
FROM Applications a JOIN Applications_Installed ai ON
a.Application_Code = ai.Application_Code
JOIN Workstation_Info wi ON ai.Computer_Name = wi.Computer_name
WHERE a.application_code = 'XXX'

May I also suggest that you pick up a reference guid on basic SQL;
newsgroups can be harsh teachers :) Years ago, I found Ben Forta's 10
Minute Guide very good at covering the basic concepts:

http://www.amazon.com/exec/obidos/t...524660?v=glance

HTH,
Stu|||Thanks Stu.......

I'll give it a try and let you know how things go.........

Cheers|||Thanks Stu.......

I'll give it a try and let you know how things go.........

Cheers|||use ACCESS DATA PROJECTS they allow you to drag and drop fields around
instead of getting frustrating writing queries.

TSQL is too hard to just dive into -- use ADP as a crutch to help you
to start getting things done and stop worrying about syntax.|||(aaron.kempf@.gmail.com) writes:
> use ACCESS DATA PROJECTS they allow you to drag and drop fields around
> instead of getting frustrating writing queries.
> TSQL is too hard to just dive into -- use ADP as a crutch to help you
> to start getting things done and stop worrying about syntax.

I would say that this is a poor advice in the long run. Maybe if you
only compose a query once or twice a year maybe. But else learning
SQL syntax pays off.

And using Access may not necessarily be helpful, since there are
significant differences between the SQL in Access and Transact-SQL.

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp

No comments:

Post a Comment