I have the SQL below. SQL return a Users.Id which are not found in Order table. I need to create Insert SQL and insert default order for these users. How to do that?
SELECT Id
FROM [User] WHERE Id NOT IN (SELECT UserId FROM dbo.[Order])
Order table columns are
Id , -- Random Number
UserId , -- Id from Select above
FirstName ,
LastName ,
Credits
Assuming
dbo.[User]has theFirstName,LastNameandCreditscolumns you can do it like this:You can see here for another example. You might understand it 🙂
To generate the
Unique Iduse the Identity Property.