Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
tech
Starting Member
32 Posts |
Posted - 2012-05-30 : 19:44:47
|
I have 2 tables:usersuserattributesI wish to insert data into userattributes where the userID in does not exist from the users table into the userattributes table.how would I do this? |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2012-05-30 : 21:07:23
|
[code]INSERT INTO userattributes ( userID, . . . )SELECT u.userID, . . .FROM users uWHERE NOT EXISTS (SELECT * FROM userattributes a WHERE a.userID = u.userID)[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
SQL Basic
Starting Member
8 Posts |
Posted - 2012-05-31 : 06:02:39
|
Also, you can modify with this code below :INSERT INTO table2 (file_index, celeb_name)SELECT file_index, 'userID'FROM table1WHERE filename = 'user' AND file_index NOT IN (SELECT DISTINCT file_index FROM table2 WHERE user_name = 'userID') |
 |
|
|
|
|