473,399 Members | 3,919 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Selecting the Same Coloumn Twice

5
Hey all...first time to the site so excuse me for bein some what of a noob to how to properly ask questions.

Im looking to create a table which selects a cloumn from another table twice.

so i have a table of customers
Name Type
CUST_ID NUMBER
FIRSTNAME VARCHAR2(40)

and a table of calls
Name Type
CALLER_CUST_ID NUMBER(2)
CALLER_FIRSTNAME VARCHAR2(40)
RECEIVER_CUST_ID NUMBER(2)
RECEIVER_FIRSTNAME VARCHAR2(40)

im looking to populate table calls with
CALLER_CUST_ID = CUST_ID, CALLER_FIRSTNAME = FirstName
and
RECEIVER_CUST_ID = CUST_ID, RECEIVER_FIRSTNAME = FIRSTNAME.

the code ive been playing around with is
Expand|Select|Wrap|Line Numbers
  1. INSERT INTO calls (
  2. caller_cust_ID , caller_firstname,receiver_cust_ID , receiver_firstname)
  3.  
  4. SELECT cust_ID , firstname, cust_ID , firstname FROM
  5. (SELECT cust_ID , firstname, cust_ID , firstname FROM custumer
  6. ORDER BY DBMS_RANDOM.VALUE
  7. )
  8. WHERE ROWNUM = 1;

Im getting an Column Ambigiguosly Defined error
Feb 12 '08 #1
9 6155
mafaisal
142 100+
Hello

Try This
Expand|Select|Wrap|Line Numbers
  1. INSERT INTO calls (
  2. caller_cust_ID , caller_firstname,receiver_cust_ID , receiver_firstname)
  3.  
  4. SELECT cust_ID , firstname, cust_ID2 , firstname2 FROM
  5. (SELECT cust_ID , firstname, cust_ID as cust_ID2  , firstname as firstname2 FROM custumer
  6. ORDER BY DBMS_RANDOM.VALUE
  7. )
  8. WHERE ROWNUM = 1;
  9.  
ie, Using of Alias Name

Hope this may help, if not Plz ignore
Feb 12 '08 #2
use aliase name for tables respective columns
Feb 13 '08 #3
debasisdas
8,127 Expert 4TB
You need to qualify the column name by table name.
Feb 13 '08 #4
niz182
5
hey guys thanks for the help, the only problem im gettign with that code is that its selecting the same data for both the caller and the reciever

CALLER_CUST_ID CALLER_FIRSTNAME RECEIVER_CUST_ID RECEIVER_FIRSTNAME
3 David 3 David

where im looking to have 2 diferent values selected.
Feb 14 '08 #5
amitpatel66
2,367 Expert 2GB
hey guys thanks for the help, the only problem im gettign with that code is that its selecting the same data for both the caller and the reciever

CALLER_CUST_ID CALLER_FIRSTNAME RECEIVER_CUST_ID RECEIVER_FIRSTNAME
3 David 3 David

where im looking to have 2 diferent values selected.
You mean to say you want to randomly insert two different values each for caller and receiver respectively?
Feb 15 '08 #6
niz182
5
You mean to say you want to randomly insert two different values each for caller and receiver respectively?

yeh, so it selects a caller from cust_details, then it selects a reciever from the same table.
Feb 15 '08 #7
amitpatel66
2,367 Expert 2GB
yeh, so it selects a caller from cust_details, then it selects a reciever from the same table.
Try this:

Expand|Select|Wrap|Line Numbers
  1.  
  2. INSERT INTO calls (
  3. caller_cust_ID , caller_firstname,receiver_cust_ID , receiver_firstname)
  4. SELECT x.ccid , x.cfn , y.rcid , y.rfn FROM
  5. (SELECT cust_ID ccid , firstname cfn, FROM custumer) x, (SELECT cust_id rcid, firstname rfn FROM customer) y 
  6. WHERE x.custid != y.custid
  7.  
  8.  
The above query will insert many combinations of caller, receiver.

I hope this helps!!
Feb 15 '08 #8
niz182
5
Try this:

Expand|Select|Wrap|Line Numbers
  1.  
  2. INSERT INTO calls (
  3. caller_cust_ID , caller_firstname,receiver_cust_ID , receiver_firstname)
  4. SELECT x.ccid , x.cfn , y.rcid , y.rfn FROM
  5. (SELECT cust_ID ccid , firstname cfn, FROM custumer) x, (SELECT cust_id rcid, firstname rfn FROM customer) y 
  6. WHERE x.custid != y.custid
  7.  
  8.  
The above query will insert many combinations of caller, receiver.

I hope this helps!!
when i run that script i get the following error...

WHERE x.custid != y.custid
*

ERROR at line 5:
ORA-06553: PLS-306: wrong number or types of arguments in call to 'OGC_X'

any idea what that means?
Feb 15 '08 #9
amitpatel66
2,367 Expert 2GB
when i run that script i get the following error...

WHERE x.custid != y.custid
*

ERROR at line 5:
ORA-06553: PLS-306: wrong number or types of arguments in call to 'OGC_X'

any idea what that means?
it should be x.ccid != x.rcid

add this condition add try to execute the query
Feb 15 '08 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

12
by: Alexander Schmolck | last post by:
Quite a few algortihms prominently feature choosing/removing a single random element from a set at a time. On first sight I can't think of anything better to achieve this with `sets.Set` than...
0
by: Wade Williams | last post by:
Imagine you've got the following situation (Oracle 9i): Table A ------------------- Name Customer Log_Date Log_Type
8
by: Agoston Bejo | last post by:
Take a look at the following example: table T(i INTEGER, j INTEGER) I want to get the value of i where j is minimal and some conditions apply. (1) SELECT i FROM T WHERE AND j
2
by: Phillip Parr | last post by:
Hey all, I'm probably just having a lax moment but I can't quite figure this out. Say I have a table such as this: friends user friend 1 2 1 3 2 4 2 1
3
by: Eric | last post by:
Hi : From a crystal report i get a list of employee firstnames as a string into my store procedure. Why is it comming this way ? hmmmmmm it's a question for me too. ex: "e1,e2,e3" here are my...
2
by: Dag | last post by:
Hi I am pretty much an xml beginner; hopefully someone can easily answer this one... I want to select a node representing a worksheet in an xml document for the Office Web Components spreadsheet....
3
by: Bruce Wood | last post by:
Maybe I'm going nuts, but I was so sure that adding the same method more than once to a delegate would result in only one entry on the delegate's call list: this.UpdateEnd += new...
16
by: Vikas Kumar | last post by:
i am selectin some data from database and through reader showing it in datalist as above now for radio buttons i have single column which returns 1,2,3 and according to that i want one of above...
3
by: supermen | last post by:
to all, how to split a column into 5 coloumn. e.g column= 1 2 1 3 4 into colomn1 = 1 colomn2 = 2 colomn3 = 1 colomn4 = 3 colomn5 = 4
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.