Tag : groupBy()


MySql comma separated column join in PHP Laravel 5

If we work in big application or project of Laravel Framework, sometimes we require to manage column value into comma separated because we can save memory of database. But if we store comma separated value in column with ids then it's difficult to inner join or left join and get records from another tables. However, SQL provide FIND_IN_SET() for checking value one by one, that way we can also search from comma separated value. FIND_IN_SET() will help to join with tables and we can simply get data. In this post, I will give you full example of how to get data from comma separated column table.....

By Hardik Savani | January 7, 2017 | | 356 Viewer | Category : PHP Laravel MySql SQL
READ MORE

How to use groupby having with DB::raw in Laravel Query Builder?

We most probably require to use group by having because if you work on small project then it's not need to use generally. But if you work with big project like e-commerce, social or ERP level project then you may require to use having clause. having clause, we can use simply if we have to compare with number or static value like as bellow: <pre> ->having("total_quantity","<",10) </pre> But we need to compare with 10 instead of column name then it can't directly use column name. At that time we should use DB::raw() with column name. In this example i want to show minimum quantity items, I .....

By Hardik Savani | July 6, 2016 | | 1034 Viewer | Category : Laravel
READ MORE

Group by year month example in Laravel 5 using Query Builder

Sometimes, we have created_at column with timestamp and we wanted to get with group by with month, that way we can use for chart. However, you can do it using mysql MONTH() function. we can use DB raw with mysql function and get group by monthly records. So, you can see bellow query and use it. <strong>Example:</strong> <pre class="prettyprint lang-php"> DB::table("clicks") ->select("id" ,DB::raw("(COUNT(*)) as total_click")) ->orderBy('created_at') ->groupBy(DB::raw("MONTH(created_at)")) ->get(); </pre>

By Hardik Savani | June 20, 2016 | | 1977 Viewer | Category : Laravel
READ MORE

How to group by multiple columns in Laravel Query Builder?

Sometimes we may require to add group by with multiple columns, if we have mysql query then we can do it easily by using sql query. But if you want to give multiple columns in groupBy() of Laravel Query Builder then you can give by comma separated values as bellow example. <strong>Example:</strong> <pre class="prettyprint lang-php"> $data = DB::table("items_count") ->select( 'items_count.*' ,DB::raw("SUM(items_count.quantity) as total_quantity")) ->groupBy('items_count.id_item','items_count.id_cat') ->get(); print_r($data); </pre>

By Hardik Savani | June 12, 2016 | | 1640 Viewer | Category : Laravel
READ MORE

    PHP Script - Login with Facebook using facebook-php-sdk and MySQL example with demo

    PHP Script - Login with Facebook using facebook-php-sdk and MySQL example with demo

    Open Post

    Laravel 5 - Authenticate user in NodeJS with socket io using JWT.

    Laravel 5 - Authenticate user in NodeJS with socket io using JWT.

    Open Post

    How to use groupby having with DB::raw in Laravel Query Builder?

    How to use groupby having with DB::raw in Laravel Query Builder?

    Open Post

    Laravel 5 create Custom Validation Rule example.

    Laravel 5 create Custom Validation Rule example.

    Open Post

    Laravel guzzle http client POST request example

    Laravel guzzle http client POST request example

    Open Post

    How to send mail using zoho smtp server in PHP Laravel?

    How to send mail using zoho smtp server in PHP Laravel?

    Open Post