mysqlwith-clause

How to use With and Values in Mysql


I have a question, how can I use 'with clause' with params in mysql as I used to do in postgre sql, i.e. using with and values, like below example :

Postgresql:

with params(idmodelo) as (values(10))
select * from modelo where idmodelo  = (select idmodelo from params)

Solution

  • The VALUES statement is implemented in MySQL 8.0.19 and later. If you use an earlier version, you must upgrade.

    mysql> select version();
    +-----------+
    | version() |
    +-----------+
    | 8.0.32    |
    +-----------+
    
    mysql> with params(idmodelo) as (values row(10)) 
           select * from params;
    +----------+
    | idmodelo |
    +----------+
    |       10 |
    +----------+
    

    For more details, read the manual entry on the VALUES statement