MySql comma separated column join using PHP Laravel

Today, We want to share with you MySql comma separated column join using PHP Laravel.In this post we will show you Search Comma Separated values using FIND_IN_SET in Laravel Query Builder, hear for MySQL query with join and comma separated values in column in Laravel we will give you demo and example for implement.In this post, we will learn about php Laravel join two tables using a comma-separated-list with an example.

MySql comma separated column join using PHP Laravel

There are the Following The simple About MySql comma separated column join using PHP Laravel Full Information With Example and source code.

As I will cover this Post with live Working example to develop find_in_set mysql,find in set in laravel ? example, so the use FIND_IN_SET in Laravel 5.1 with where raw method for this example is following below.

Syntax find_in_set() method

FIND_IN_SET(needle,haystack);

Step 1: Simple SQL Query

SELECT
    `live_products`.*, GROUP_CONCAT(products.name) as productname 
FROM `live_products` 
LEFT JOIN `products` ON FIND_IN_SET(products.id,live_products.products) > '0' 
GROUP BY `live_products`.`id`

And then I can convert this Core sql query into PHP Latest Framework laravel, Therefor I can use Laravel FIND_IN_SET() in MySQL like as bellow simple convert query example using Laravel Query Builder:

Step 2: Laravel 5.7 MySql Query Builder:

$data = \DB::table("live_products")
        ->select("live_products.*",\DB::raw("GROUP_CONCAT(products.name) as productname"))
        ->leftjoin("products",\DB::raw("FIND_IN_SET(products.id,live_products.products)"),">",\DB::raw("'0'"))
        ->groupBy("live_products.id")
        ->get();

at the last You can below see output will be like as Example as a:

Step 3: Final Output

Illuminate\Support\Collection Object
(
    [items:protected] => Array
        (
            [0] => stdClass Object
                (
                    [id] => 1
                    [name] => How to install LaravelBook?
                    [products] => 1,2
                    [created_at] => 2019-01-06 00:00:00
                    [updated_at] => 2019-01-06 00:00:00
                    [productname] => PHPBook,LaravelBook
                )
            [1] => stdClass Object
                (
                    [id] => 2
                    [name] => How to work with PHPBook?
                    [products] => 1
                    [created_at] => 2019-01-06 00:00:00
                    [updated_at] => 2019-01-06 00:00:00
                    [productname] => PHPBook
                )
        )
)
Angular 6 CRUD Operations Application Tutorials

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about MySql comma separated column join using PHP Laravel.
I would like to have feedback on my Pakainfo.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Leave a Comment