phpmysqlcodeigniterselectquery-builder

MYSQL ERROR 1096 - NO TABLES USED - CODEIGNITER


I am using a custom query as the Active Record equivelant did not work for me.

When placing the Query in my Database Software SQLYOG it works fine however in CodeIgniter it says

A Database Error Occurred

Error Number: 1096

No tables used

SELECT *

Filename: C:\xampp\htdocs\midas\system\database\DB_driver.php

Line Number: 330

Here is my Query:

SELECT intervention.department_id, department_name, COUNT(*)
FROM intervention 
LEFT JOIN department ON department.department_id = intervention.department_id

GROUP BY intervention.department_id, department.department_name
ORDER BY COUNT(*) desc
LIMIT 1

It is a bit of a strange problem.

Here is my Schema also:

https://i.sstatic.net/WstcX.png


Solution

  • EDIT

    This will not work. As noted below only COUNT(*) or COUNT(table.field) work.

    I think you need to specify which table you are using COUNT(*) on, so change it to something like COUNT(department.*) or COUNT(intervention.*)