Hello There, Guest!
View New Posts  |  View Today's Posts
Joining Tables in SQL ?

  • 0 Vote(s) - 0 Average


02-22-2015, 08:24 PM #1
william7
Member
**
Posts: 205 Threads:49 Joined: Feb 2012 Reputation: 0

Joining Tables in SQL ?
Below is a screenshot of my sql code and results where I've been trying to join 3 tables. I need to find the number and name of each customer that currently has an order on file for a Gas Range. I've included screenshots of the data as well. Any help you can give me with this most difficult problem will be appreciated.








02-22-2015, 10:55 PM #2
AceInfinity
Developer
*******
Administrators
Posts: 9,733 Threads:1,026 Joined: Jun 2011 Reputation: 76

RE: Joining Tables in SQL ?
You obviously can't compare CUSTOMER_NUM from PART_NUM because the datatypes are not even remotely the same. VARCHAR vs. INT Unsure (Look at the columns in your 2nd and 3rd images). This will not work:
Code:
ORDERS.CUSTOMER_NUM = PARTS.PART_NUM

Please keep only 1 thread open for all of these questions too.
This post was last modified: 02-22-2015, 11:00 PM by AceInfinity.


Microsoft MVP .NET Programming - (2012 - Present)
®Crestron DMC-T Certified Automation Programmer

Development Site: aceinfinity.net

 ▲
 ▲ ▲

02-24-2015, 03:14 AM #3
Lee Stevens
Senior Member
***
Posts: 345 Threads:54 Joined: Feb 2012 Reputation: 12

RE: Joining Tables in SQL ?
I'm confused by your query and/or setup.

From what you show you have no relation from a order and the parts ordered. First you must map ordered parts to an order then you can do something like:

Code:
SELECT C.CUSTOMER_NUM, C.CUSTOMER_NAME, O.ORDER_NUM, P.DESCRIPTION_ FROM CUSTOMER C
    INNER JOIN ORDERS O ON O.CUSTOMER_NUM = C.CUSTOMER_NUM         // JOIN CUSTOMER AND ORDER
    INNER JOIN ORDER_TO_PART OP ON O.ORDER_NUM = OP.ORDER_NUM    // JOIN ORDER TO ORDERED PARTS (ID)
    INNER JOIN PARTS P ON OP.PART_NUM = P.PART_NUM            // JOIN PART FROM PART_NUM IN ORDERED PARTS FOR ORDER
WHERE
    P.PART_NUM = 'DR93'




Forum Jump:



Users browsing this thread: 1 Guest(s)