0 votes
1 view
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.4k 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 in SQL by Sudhir_1997 (47.2k points)
0 votes
1 answer
0 votes
1 answer
asked Jul 13, 2019 in SQL by Tech4ever (20.3k points)
+2 votes
1 answer
0 votes
1 answer
asked Jul 18, 2019 in SQL by Tech4ever (20.3k points)
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...