SQL Best Practices: Difference between revisions
Jump to navigation
Jump to search
(Created page with "== Determining if a record exists == <syntaxhighlight lang="sql"> SELECT EXISTS (SELECT 1 FROM users_table WHERE user_table.userid = p_userId) INTO p_isPresent; </syntaxhighlight> Not <syntaxhighlight lang="sql"> SELECT COUNT(*) FROM users_table WHERE user_table.userid = p_userId INTO p_isPresent; </syntaxhighlight> `SELECT EXISTS` stops as soon as it finds a match. `COUNT` counts all matches. Category:MySQLCategory:MariaDB") |
(No difference)
|
Latest revision as of 11:28, 7 January 2022
Determining if a record exists[edit]
SELECT EXISTS (SELECT 1 FROM users_table WHERE user_table.userid = p_userId) INTO p_isPresent;
Not
SELECT COUNT(*) FROM users_table WHERE user_table.userid = p_userId INTO p_isPresent;
SELECT EXISTS stops as soon as it finds a match. COUNT counts all matches.