coldhands
coldhands

Reputation: 457

Is there a MySQL equivalent of the WITH keyword in Oracle

I am currently trying to convert some Oracle SQL to MySQL and came across the WITH keyword in Oracle. Is there an equivalent of WITH in MySQL? Thanks

WITH example in Oracle:

with cus as (select id from tb_company where id=3)
select * from cus;

Upvotes: 0

Views: 173

Answers (1)

wolφi
wolφi

Reputation: 8361

Yes, there is an equivalent since MySQL version 8.0:

WITH
  cte1 AS (SELECT a, b FROM table1),
  cte2 AS (SELECT c, d FROM table2)
SELECT b, d FROM cte1 JOIN cte2
 WHERE cte1.a = cte2.c;

https://dev.mysql.com/doc/refman/8.0/en/with.html

Upvotes: 1

Related Questions