How do i use the top keyword in an insert statement?
I was using it as LIMIT when I got the exception Incorrect syntax near the keyword 'TOP'
.
Maybe I 开发者_StackOverflow社区can omit it in this case without a problem, but if I couldn't where do I put top?
INSERT INTO [user_data] (...) SELECT
...
@14 WHERE not exists (SELECT * FROM [user_data] WHERE [email] = @15 OR
[name] = @16 OR
[unconfirmed_email] = @17 TOP 1);
TOP
goes after SELECT
in SQL Server, not like where LIMIT
goes in other DBMSes.
SELECT TOP 1 <fields> FROM ...
So your query would become:
INSERT INTO [user_data] (...) SELECT
...
@14 WHERE not exists (SELECT TOP 1 * FROM [user_data] WHERE [email] = @15 OR
[name] = @16 OR
[unconfirmed_email] = @17);
精彩评论