Home » SQL & PL/SQL » SQL & PL/SQL » SQL join question (oracle 8.)
SQL join question [message #320589] Thu, 15 May 2008 10:28 Go to next message
sguider
Messages: 8
Registered: May 2008
Junior Member
I am trying to pull data from two tables one of which doesn't have a column which I can use to join to the other table. How might I approach this?

Thanks
Re: SQL join question [message #320592 is a reply to message #320589] Thu, 15 May 2008 10:31 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
http://www.orafaq.com/forum/t/88153/0/
Please read & follow posting guidelines as stated in URL above
Re: SQL join question [message #320596 is a reply to message #320589] Thu, 15 May 2008 10:39 Go to previous messageGo to next message
sguider
Messages: 8
Registered: May 2008
Junior Member
the table desc are below

Name Null? Type
------------------------------- -------- ----
UTVCRAT_CODE NOT NULL VARCHAR2(1)
UTVCRAT_DESC NOT NULL VARCHAR2(35)
UTVCRAT_MAX_POINTS NOT NULL NUMBER(4)
UTVCRAT_ACTIVITY_DATE NOT NULL DATE
UTVCRAT_USER_ID NOT NULL VARCHAR2(30)



Name Null? Type
------------------------------- -------- ----
UCBCUST_PIDM NUMBER(Cool
UCBCUST_CUST_CODE NOT NULL NUMBER(9)
UCBCUST_LAST_NAME NOT NULL VARCHAR2(60)
UCBCUST_LAST_NAME_SDX NOT NULL VARCHAR2(4)
UCBCUST_STATUS_IND NOT NULL VARCHAR2(1)
UCBCUST_START_DATE NOT NULL DATE
UCBCUST_ACTIVITY_DATE NOT NULL DATE
UCBCUST_USER_ID NOT NULL VARCHAR2(30)
UCBCUST_1099_IND NOT NULL VARCHAR2(1)
UCBCUST_FIRST_NAME VARCHAR2(15)
UCBCUST_FIRST_NAME_SDX VARCHAR2(4)
UCBCUST_MIDDLE_NAME VARCHAR2(15)
UCBCUST_MIDDLE_NAME_SDX VARCHAR2(4)
UCBCUST_SSN VARCHAR2(12)
UCBCUST_DRIVERS_LICENSE VARCHAR2(15)
UCBCUST_ETHN_CODE VARCHAR2(2)
UCBCUST_CREDIT_RATING VARCHAR2(1)
UCBCUST_EMPLOYER VARCHAR2(20)
UCBCUST_MMBR_CODE RAW(1)
UCBCUST_PAY_BY_CHECK_IND VARCHAR2(1)
UCBCUST_SPOUSES_NAME VARCHAR2(15)
UCBCUST_END_DATE DATE
UCBCUST_BMSG_CODE VARCHAR2(4)
UCBCUST_1099_ID VARCHAR2(12)
UCBCUST_1099_WH_PCT NUMBER(5,3)
UCBCUST_1099_STATE VARCHAR2(3)
UCBCUST_NATN_CODE_D_L VARCHAR2(5)
UCBCUST_STAT_CODE_D_L VARCHAR2(3)
UCBCUST_SPOUSES_SSN VARCHAR2(12)
UCBCUST_1099_PRIMARY_IND VARCHAR2(1)

[Updated on: Thu, 15 May 2008 10:40]

Report message to a moderator

Re: SQL join question [message #320598 is a reply to message #320589] Thu, 15 May 2008 10:45 Go to previous messageGo to next message
Michel Cadot
Messages: 68737
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
Quote:
one of which doesn't have a column which I can use to join to the other table.

So you can't join them.

Regards
Michel
Re: SQL join question [message #320633 is a reply to message #320596] Thu, 15 May 2008 13:22 Go to previous messageGo to next message
joy_division
Messages: 4963
Registered: February 2005
Location: East Coast USA
Senior Member
Quote:
I am trying to pull data from two tables one of which doesn't have a column which I can use to join to the other table.


I am assuming you meant neither has a column which you can use to join because if one does, then the other does to, and if one doesn't, the other doesn't either.


select * from UTVCRAT;
select * from UCBCUST;


QED

Do you really preface each column with the name of the table? Of course I made an assumption that these were the names of the tables since you didn't paste an actual session. You also did not use CODE tags to make your message readable.

[Updated on: Thu, 15 May 2008 13:24]

Report message to a moderator

Re: SQL join question [message #320647 is a reply to message #320633] Thu, 15 May 2008 14:34 Go to previous messageGo to next message
sguider
Messages: 8
Registered: May 2008
Junior Member
Since it's not code I didn't think it was necessary to use the code tags. It's just a copy paste of the desc of the tables.
Re: SQL join question [message #320650 is a reply to message #320633] Thu, 15 May 2008 14:35 Go to previous messageGo to next message
sguider
Messages: 8
Registered: May 2008
Junior Member
I don't want to select everything from the tables
Re: SQL join question [message #320651 is a reply to message #320647] Thu, 15 May 2008 14:38 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
sguider wrote on Thu, 15 May 2008 12:34
It's just a copy paste of the desc of the tables.

Where as the Posting Guidelines clearly state -
" Provide DDL (CREATE TABLE, etc.) as appropriate instead of listing the table structure."

>I don't want to select everything from the tables
& EXACTLY how are supposed to KNOW this detail?

You're On Your Own!

[Updated on: Thu, 15 May 2008 14:38] by Moderator

Report message to a moderator

Re: SQL join question [message #320654 is a reply to message #320651] Thu, 15 May 2008 14:49 Go to previous messageGo to next message
sguider
Messages: 8
Registered: May 2008
Junior Member
I sought out a forum trying to find help to complete a task. I asked the questions the best way that I knew to being that I am a newbie at this. This forum has not been of much help but instead in my opinion has broken some of its own basic rules:

"Some of the most important instructions are:



Be polite!

Never belittle anyone for asking beginner-level questions or for their English skills."

Re: SQL join question [message #320663 is a reply to message #320654] Thu, 15 May 2008 15:54 Go to previous messageGo to next message
Littlefoot
Messages: 21823
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
Here's your situation:
SQL> CREATE TABLE t_first
  2  (id   NUMBER,
  3   name VARCHAR2(20)
  4  );

Table created.

SQL> CREATE TABLE t_second
  2  (height NUMBER,
  3   weight NUMBER
  4  );

Table created.

SQL> INSERT ALL
  2    INTO t_first (id, name) VALUES (1, 'Little')
  3    INTO t_first (id, name) VALUES (2, 'Foot')
  4    INTO t_second (weight, height) VALUES (175, 73)
  5    INTO t_second (weight, height) VALUES (190, 110)
  6  SELECT * FROM dual;

4 rows created.

SQL> SELECT * FROM t_first;

        ID NAME
---------- --------------------
         1 Little
         2 Foot

SQL> SELECT * FROM t_second;

    HEIGHT     WEIGHT
---------- ----------
        73        175
       110        190

SQL>

Now, what result do you expect (based on this simple example), other than two separated SELECT queries?

Would you like to "join" those tables? No problem! It is called a Cartesian join and looks like this:
SQL> SELECT * FROM t_first, t_second;

        ID NAME                     HEIGHT     WEIGHT
---------- -------------------- ---------- ----------
         1 Little                       73        175
         1 Little                      110        190
         2 Foot                         73        175
         2 Foot                        110        190

SQL>
Which combination is true? Which is not? Can you tell? I can't.

So - what do you, really, want?
Re: SQL join question [message #320692 is a reply to message #320589] Thu, 15 May 2008 23:02 Go to previous message
Michel Cadot
Messages: 68737
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
I advice you to read this section of SQL Reference: Joins.

Regards
Michel
Previous Topic: Database design document
Next Topic: emp table
Goto Forum:
  


Current Time: Sat Feb 15 02:25:39 CST 2025