Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 366
  • Last Modified:

is there any advantage of doing select count(*) from table instead of select col

hello,
I need to check for the existence of a dir in a table

is there any advantage/disadvantage of doing
select count(dir) from table where dir = 'dir'
vs
select dir from table where dir = 'dir'

Thanks
0
paries
Asked:
paries
1 Solution
 
Easwaran ParamasivamCommented:
Yes. select count(dir) from table where dir = 'dir' returns only the count of the dir column.

You can fine tune as below. This will be even more faster. It will select only one row even more rows exist in the table.

select TOP 1 from table where dir = 'dir'



0
 
EyalCommented:
if exists(select top 1 dir from table where dir = 'dir') is the right way
0
 
pariesAuthor Commented:
EaswaranP:

select TOP 1 from mke_users where dir = 'dir'
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1 from mke_users where dir = 'dir'' at line 1

0
 
Easwaran ParamasivamCommented:
Sorry I missed out the column name there.. That should be as select TOP 1 dir from mke_users where dir = 'dir'
0
 
Pratima PharandeCommented:
if you want to check whether any record exists or not

try this

select dir from table where dir = 'dir' limit 1

this will return one row if record exists otherwise no rows
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now