Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

SarjitDelivala's avatar

How to execute Cross join using Raw Query?

I have an SQL query that I want to convert to Laravel DB Query. But, I am unsure how to use Raw Query for Cross Joins.

SELECT DISTINCT json_t.id
FROM my_table,
  JSON_TABLE(my_table.array_ids, "$[*]" COLUMNS(id char(36) PATH "$")) AS json_t
WHERE my_table.array_ids IS NOT NULL

Can someone please help me to convert this query into Laravel DB Query?

0 likes
1 reply
Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102
DB::selectRaw('SELECT DISTINCT json_t.id
FROM my_table,
  JSON_TABLE(my_table.array_ids, "$[*]" COLUMNS(id char(36) PATH "$")) AS json_t
WHERE my_table.array_ids IS NOT NULL')->get();
1 like

Please or to participate in this conversation.