How do I insert (or generate and insert) a primary key when I use the
SELECT DISTINCT query?
If I have a table made like this:
CREATE TABLE testUser( username VARCHAR2(50 CHAR), email VARCHAR2(50 CHAR) )
And I had some table
customer_orders with this data I could quickly populate this using:
INSERT INTO testUser(username, email) SELECT DISTINCT user_name, user_email FROM customer_info;
However if instead I have this table:
CREATE TABLE users( id NUMBER, user_name VARCHAR2(50 CHAR), user_email VARCHAR2(50 CHAR) )
and try to use the same method (the
SELECT DISTINCT INSERT method) I'll get an error like
ORA-01400: cannot insert NULL into ("MYDB"."USERS"."ID").
This makes sense since the primary key is null, how can I autogenerate a primary key
n is the
COUNT(SELECT DISTINCT user_name)?