Skip to content

Tag: sql

sql SUM: change null with 0

I have a query like this: And another like this: I want to select from those tables, with condition But I also want to change the null record which appears with 0, I’ve tried COALESCE but it still doesn’t give me the right result. Answer In general you would first set NULL values to 0 and then SUM…

Laravel using where clause on a withCount method

I am trying to do a where clause on withCount method of laravel’s eloquent query builder using this piece of code. and this code is giving me this error. SQLSTATE[42S22]: Column not found: 1054 Unknown column ‘upvotes_count’ in ‘where clause’ (SQL: select , (select count() from u…