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:
* Get free support
* Communicate privately with other members (PM).
* Removal of this message
* 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
Go Back   Tech Support Forum > The IT Pro > Programming
User Name
Password
Site Map Register Donate Rules Blogs Mark Forums Read


Programming A discussion forum for programs and programming used in tech-related businesses.

Reply
 
LinkBack Thread Tools
Old 05-04-2009, 12:45 AM   #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
kevkgho is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
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

Old 05-06-2009, 11:41 PM   #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.
Ptroy is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 05-08-2009, 04:08 PM   #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')
Jim_from_Oz is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT -7. The time now is 09:48 PM.



Copyright 2001 - 2009, Tech Support Forum
Home Tips Plus | Outdoor Basecamp | Automotive Support Forum

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85