Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL count - not working

Tags:

I am trying this code:

SELECT COUNT (oferta_id_oferta)  FROM `oferta_has_tags`  WHERE oferta_id_oferta =  (SELECT id_oferta FROM oferta  WHERE oferta = "designer") 

I receive error: 1630 - FUNCTION mydb.COUNT does not exist. Check the 'Function Name Parsing and Resolution' section in the Reference Manual

If I remove the COUNT word, I get two results.

What is the problem?

like image 533
user947462 Avatar asked Oct 20 '11 18:10

user947462


People also ask

How does count (*) work in SQL?

COUNT(*) returns the number of rows in a specified table, and it preserves duplicate rows. It counts each row separately. This includes rows that contain null values.

Can we use count (*)?

The simple answer is no – there is no difference at all. The COUNT(*) function counts the total rows in the table, including the NULL values.

Does count () Count zero?

The result is a BIGINT value. It is an aggregate function, and so can be used with the GROUP BY clause. COUNT(*) counts the total number of rows in a table. COUNT() returns 0 if there were no matching rows.


2 Answers

Don't put a space

SELECT COUNT(oferta_id_oferta)  FROM `oferta_has_tags`  WHERE oferta_id_oferta =  (SELECT id_oferta FROM oferta  WHERE oferta = "designer") 
like image 53
msarchet Avatar answered Oct 04 '22 22:10

msarchet


Try removing the space between COUNT and the parentheses:

SELECT COUNT(oferta_id_oferta)  FROM `oferta_has_tags`  WHERE oferta_id_oferta =  (SELECT id_oferta FROM oferta  WHERE oferta = "designer") 

Also, you can probably get rid of your subquery by joining:

SELECT COUNT(oferta_id_oferta)  FROM `oferta_has_tags`, `oferta` WHERE     oferta_has_tags.oferta_id_oferta = oferta.id_oferta     AND oferta.oferta = "designer" 
like image 22
ObscureRobot Avatar answered Oct 04 '22 22:10

ObscureRobot