[eluser]developer10[/eluser]
[quote author="sl3dg3hamm3r" date="1246968301"][quote author="cold_fusion" date="1246932852"][quote author="sl3dg3hamm3r" date="1246925996"]didn't look well at the query. Yes, 'inner' wouldn't change much. I would formulate the query different (not tested!):
Code:
SELECT dje.djelatnost, count(firme.d_id) AS firmCount
FROM tbl_djelatnosti AS dje
LEFT JOIN tbl_firme AS firme ON dje.d_id = firme.d_id
GROUP BY dje.d_id
It is way more readable like that, subquery or derived table is not necessary...[/quote]
well, it seems you included some fields that do not exist in my table
above i posted how my tables look like so you have needed field names
category table: tbl_djelatnosti, with only 2 field names: d_id and djelatnost
company table: _tbl_firme, needed fields are: f_id and d_id
here's the live example of what im trying to accomplish, link is in my signature
that's the site im trying to rebuild using CI, currently it's coded in standard PHP[/quote]
I don't think so. All fields in my example do exist (don't mix up aliases with the physical field-/table-names). You can adjust the selected fields according to your needs. Did you try at all?[/quote]
yes, i did give it a try, and it threw me an error message (dont remember which one, but certainly it was an sql error)
i think it's because an alias "dje" appears in the statement BEFORE it's defined ( SELECT
dje.djelatnost, count... )?