Home >Database >Mysql Tutorial >Does MySQL Support the WITH Clause, and If So, Since When?

Does MySQL Support the WITH Clause, and If So, Since When?

Patricia Arquette
Patricia ArquetteOriginal
2025-01-12 13:42:42954browse

Does MySQL Support the WITH Clause, and If So, Since When?

Detailed explanation of MySQL WITH clause

MySQL’s WITH clause allows you to define a named temporary result set in a query. While other relational database management systems (RDBMS) such as Oracle and Microsoft SQL Server support this feature, MySQL historically has not.

A user recently encountered this limitation while trying to create a view using the WITH clause:

<code class="language-sql">WITH authorRating(aname, rating) AS
   SELECT aname, AVG(quantity)
   FROM book
   GROUP BY aname</code>

MySQL 8.0 update

With clauses were not supported in MySQL versions prior to 8.0, but MySQL 8.0 finally introduced common table expressions (CTEs), including recursive CTEs. This feature is a welcome addition that brings MySQL into line with other RDBMS.

MySQL versions before 8.0

Before MySQL 8.0, there was no direct way to use the WITH clause in MySQL. This feature has existed as a requested feature since 2006.

The above is the detailed content of Does MySQL Support the WITH Clause, and If So, Since When?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn