Computing.Net > Forums > Database > SQL Question about DISTINCT

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

SQL Question about DISTINCT

Reply to Message Icon

Name: kaztuba1
Date: November 12, 2007 at 19:35:08 Pacific
OS: XP
CPU/Ram: 2GB
Product: DELL
Comment:

I have a empty table A that I am trying to populate.

Insert into A(primary_key, Name)
Select sequence.NEXTVAL, name
From Table B


The problem is that name in B have duplicate values and I cant use DISTINCT with SELECT because of the sequence. How do I make name distinct and still populate the primary key with the sequence.

Any help would be great!!! Thanks!!!




Sponsored Link
Ads by Google

Response Number 1
Name: Mahesh Kumar
Date: November 18, 2007 at 19:52:06 Pacific
Reply:

I am not sure but may be you can create another table C based on table B.
Create table C
SELECT DISTINCT name FROM table b;
Then
Insert into A(primary_key, Name)
Select sequence.NEXTVAL, name
From Table C

Try if this works.

Regards,
Mahesh Kumar


0

Response Number 2
Name: Razor2.3
Date: November 29, 2007 at 10:02:27 Pacific
Reply:

I'm rusty with my SQL, but couldn't you do this?

INSERT INTO A(primary_key, Name)
SELECT sequence.NEXTVAL, name
FROM SELECT DISTINCT name
FROM B;


0

Response Number 3
Name: mwatterud
Date: February 19, 2008 at 09:42:40 Pacific
Reply:

INSERT INTO A(Primary_key, Name)
SELECT
XX.NextVal
,XX.Name
FROM (SELECT
MIN(sequence.NEXTval) AS NextVal
,Name
FROM TABLE B
GROUP BY Name) XX


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Database Forum Home


Sponsored links

Ads by Google


Results for: SQL Question about DISTINCT

oracle 9i sql question www.computing.net/answers/dbase/oracle-9i-sql-question/649.html

SQL2005 stored procedure question www.computing.net/answers/dbase/sql2005-stored-procedure-question/199.html

SQL Question www.computing.net/answers/dbase/sql-question/83.html