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
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.
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
Summary: hi all, have a sql question. i have a table which has a column varchar2(10) which holds employee numbers e.g 'X1234'. I need to update these and change them to lower case 'x' whereever they are ...
Summary: Hi people, I have a question about SQL 2005 stored procedures. I have a stored procedure that determins the current price of a stock item and I want to be able to 'select' the value when querying the ...
Summary: Hello, i am interested in learning Microsoft SQL, and possible take a low level cert. I would like to start off as inexpensive as possible, so this weekend i will be installing, and configuring MySQL....