![]() |
![]() |
![]() |
|||||
![]() |
![]() |
![]() |
![]() |
![]() |
|||
| Welcome
to Tech Support Forum home to more then 136,000 problems solved. Issues
have included: Spyware, Malware, Virus Issues, Windows, Microsoft,
Linux, Networking, Security, Hardware, and Gaming Getting your
problem solved is as easy as: 1. Registering for a free account 2. Asking your question 3. Receiving an answer Registered members: * See fewer ads. * And much more..
|
| Want to know how to post a question? click here | Having problems with spyware and pop-ups? First Steps |
|
|||||||
| Programming A discussion forum for programs and programming used in tech-related businesses. |
![]() |
|
|
LinkBack | Thread Tools |
|
|
#1 (permalink) |
|
Registered User
Join Date: May 2009
Posts: 1
OS: vista
|
SQL multi table query - is this possible ?
I am new to SQL and I wonder if this can be done.
I have 3 tables: Table "SITES" -------------------------------------- SITEID -------------------------------------- S1 S2 Table "BALANCE" -------------------------------------- PRODUCTID SITEID QTY -------------------------------------- Apple S1 120 Apple S2 50 Egg S1 60 Egg S2 0 Table "PRODUCTS" -------------------------------------- PRODUCTID -------------------------------------- Apple Egg How do I put together a query and generate a recordset like: -------------------------------------- PRODUCTID S1 S2 -------------------------------------- APPLE 120 50 Egg 60 0 I am new to SQL, please enlight me. ![]() Million thanks in advance. Peace. Kevin |
|
|
|
| Important Information |
|
Join the #1 Tech Support Forum Today - It's Totally Free!
TechSupportForum.com is a leading support website for your computer needs. We offer free, friendly and personalized computer support. Why pay to have your computer fixed when you can do it for free. Join TechSupportforum.com Today - Click Here |
|
|
#2 (permalink) |
|
Registered User
Join Date: Aug 2005
Location: Wisconsin
Posts: 62
OS: Vista Biz(x86), Server 2003 Enterprise(x86), XP Pro(x86), XP Home(x86)
|
Re: SQL multi table query - is this possible ?
This is What I think it might be like for SQL Server, didn't catch what DB you're using.
SELECT PRODUCTS.PRODUCTID, SITES.SITEID, BALANCE.QTY INNER JOIN PRODUCTS ON PRODUCTS.PRODUCTID = BALANCE.PRODUCTID INNER JOIN SITES ON SITES.SITEID = BALANCE.SITEID WHERE (SITES.SITEID = 's1' OR SITES.SITEID = 's2') AND (PRODUCTS.PRODUCTID = 'APPLE' OR PRODUCTS.PRODUCTID = 'EGG') Anyways, just a suggestion, I am no expert by any means. I'm just trying to pass along what I've learned, as I am graduating in a week. Let me know if it's ORACLE though, I did do ORACLE SQL this past summer for a company, manipulating production data for reports. I was surprised though, the Biz analyst was clueless with working with DB's so I think that is why they hired me. Anyways, I get done with that internship, then my focus is back to all programming (VB and Java) for school, now this semester its switching back to T-SQL for SQL Server, which most of my assignments this year, used. Well sorry for the jibberish, let me know what the above gives you back for errors. |
|
|
|
|
|
#3 (permalink) |
|
Registered User
Join Date: Jul 2007
Location: Born UK, Worked in Libya, Kenya, Uganda, Settled in Australia. Now resident outside Melbourne, Victoria
Posts: 19
OS: Windows XP SP2
|
Re: SQL multi table query - is this possible ?
There is a slight error in this query because the table BALANCE is not nominated. I think this should work:
SELECT PRODUCTS.PRODUCTID, SITES.SITEID, BALANCE.QTY FROM PRODUCTS INNER JOIN BALANCE ON PRODUCTS.PRODUCTID = BALANCE.PRODUCTID INNER JOIN SITES ON SITES.SITEID = BALANCE.SITEID WHERE (SITES.SITEID = 's1' OR SITES.SITEID = 's2') AND (PRODUCTS.PRODUCTID = 'APPLE' OR PRODUCTS.PRODUCTID = 'EGG') |
|
|
|
![]() |
| Thread Tools | |
|
|