Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in SQL by (20.3k points)

Reading some SQL Tuning documentation I found this:

Select count(*) :

- Counts the number of rows

- Often is improperly used to verify the existence of a record

Is Select count(*) really that bad?

What's the proper way to verify the existence of a record?

1 Answer

0 votes
by (40.7k points)

Use the code given below:

Query 1:

SELECT 1

FROM table_name

WHERE key = value;

Otherwise, you can use this query:

Query 2:

SELECT COUNT(1)

FROM table_name

WHERE key = value;

Note: The first query will give you either no result or zero result, and in the second query count should be either zero or one.

Related questions

0 votes
1 answer
asked May 4, 2020 in SQL by Sudhir_1997 (55.6k points)
0 votes
1 answer
0 votes
1 answer
asked Jul 13, 2019 in SQL by Tech4ever (20.3k points)
0 votes
1 answer
asked Jul 18, 2019 in SQL by Tech4ever (20.3k points)
0 votes
1 answer

Browse Categories

...