Oracle Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesOracle Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Generate data entry and reporting .NET Web apps in minutes, straight from your database. Read our FREE whitepaper “Build Web 2.0 Applications Without Hand-Coding” Download now!
  #1  
Old April 15th, 2004, 03:51 AM
YuLing YuLing is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 44 YuLing User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
Send a message via ICQ to YuLing
Cant display duplicate column name?

Hi,

Encounter another problem...

I have 2 tables which stores employees worktime record.
One of the tables stores record on the current month and the another table will store record from the previous month.

When i do this query...

SELECT a.emp_id, a.emp_name, a.in_time, a.out_time, a.date, b.in_time, b.out_time, b.date
FROM worktime_current a, worktime_previous b
WHERE a.emp_id = b.emp_id;

I got this error msg
ORA-00957: duplicate column name

What is wrong the query?? Cant it display a column that have the same name but from different tables???

How to modify it so that the query can work?

Thanks

--------------------------
regards,
YuLing

Reply With Quote
  #2  
Old April 15th, 2004, 09:38 AM
shammat shammat is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Oct 2003
Location: Munich, Bavaria
Posts: 972 shammat User rank is Second Lieutenant (5000 - 10000 Reputation Level)shammat User rank is Second Lieutenant (5000 - 10000 Reputation Level)shammat User rank is Second Lieutenant (5000 - 10000 Reputation Level)shammat User rank is Second Lieutenant (5000 - 10000 Reputation Level)shammat User rank is Second Lieutenant (5000 - 10000 Reputation Level)shammat User rank is Second Lieutenant (5000 - 10000 Reputation Level)shammat User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 17 h 50 m 23 sec
Reputation Power: 57
If you select columns with the same name from different tables, you need to assign a column alias for those columns:
Code:
SELECT a.emp_id,
       a.emp_name,
       a.in_time as a_in_time,
       a.out_time as a_out_time,
       a.date as a_date,
       b.in_time as b_in_time,
       b.out_time b_out_time,
       b.date as b_date
FROM worktime_current a,
     worktime_previous b
WHERE a.emp_id = b.emp_id

Reply With Quote
  #3  
Old April 15th, 2004, 09:43 AM
shafique shafique is offline
Senior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: Canada
Posts: 305 shafique User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 45 m 20 sec
Reputation Power: 5
This query suppose to work fine. If you are using this query to CREATE a new table or in INSERT clause, it will give you error message. Check your query again.

Reply With Quote
  #4  
Old April 15th, 2004, 07:23 PM
YuLing YuLing is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 44 YuLing User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
Send a message via ICQ to YuLing
Thank you...

The code work just fine as i only wants it to display the the time out, not creating a new table.

But just for some additional knowledge, incase i need to CREATE a new table in the future...what should i do if the new table that i wanted to create contain two columns that have the same column name. Do i rename either one the 2 column first before i can create the new table?? Or is there an easier way to do it??

Thanks

Ooo and btw is there any difference between
WHERE a.emp_id = b.emp_id

and

WHERE b.emp_id = a.emp_id


----------------------
YuLing

Last edited by YuLing : April 15th, 2004 at 07:26 PM.

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesOracle Development > Cant display duplicate column name?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway