-1

Possible Duplicate:
In SQL, what's the difference between count(column) and count(*)?

As per subject, is there any difference in how MySQL interprets the above query? Or they are regarded as the same?

Community
  • 1
  • 1
Andreas Wong
  • 59,630
  • 19
  • 106
  • 123
  • Have you tried them? They usually don't give the same results, so why do you think they might be considered the same? – ypercubeᵀᴹ Mar 21 '12 at 09:48
  • sorry wrong title >.<, edited – Andreas Wong Mar 21 '12 at 09:48
  • 2
    Read this (almost identical question: [What is the difference between select count(*) and select count(any_non_null_column)?](http://dba.stackexchange.com/questions/2511/what-is-the-difference-between-select-count-and-select-countany-non-null-col) – ypercubeᵀᴹ Mar 21 '12 at 09:49
  • 2
    This question has been asked millions of times. – juergen d Mar 21 '12 at 09:50
  • They should be the same. It is preferred not to use `select *`. The most common problem I faced is what happens if you want to exclude a column? See [here](http://stackoverflow.com/questions/321299/what-is-the-reason-not-to-use-select/). – cctan Mar 21 '12 at 09:51

3 Answers3

3

The difference between the functions COUNT(*) and COUNT(fieldname) is that the second does not calculate NULL-values.

Vikram
  • 8,235
  • 33
  • 47
1

SELECT *... returns all the fields in the selected tables. SELECT fieldname returns only the specified field name.

It is more efficient using the second option, specially in cases where the table has many fields and some of them are not indexed. Selecting from those will take longer, and if you don't need there is no point in selecting all.

aurbano
  • 3,324
  • 1
  • 25
  • 39
0

select(*) means you wants to select all fields available in the table. While select(fieldname) means you only want to select certain columns in the table.

For example, you have a table 'Users' with columns 'username', 'email', 'password'; you can do the following:

select (*) from Users

which will give you all 3 columns (username, email, password); or you can do:

select username, email from Users

which will only give you 2 columns (username, email).