0

I have a select statement that is built out of two select statements that are inner joined

SELECT stuff FROM
    (multiple SELECT statements) AS T1
INNER JOIN
    (SELECT stuff FROM
        (multiple SELECT statements same as T1)) AS T2 ON more stuff

What I did was copy paste T1 select statement, is there a way to give T1 a name that can be recognized in the sub query creating T2? PS Im using MySQL

Sir V
  • 31
  • 7
  • 2
    Not in MySQL, unless you are able to use a view. Other databases support CTEs. However, perhaps the subquery is not needed. – Gordon Linoff Mar 27 '17 at 15:18
  • 1
    MySQL goes out of its way to make this difficult. It doesn't have CTEs, and it also doesn't allow you to use a temporary table multiple times in a query. You have to define a view or copy the result of the query to a regular table. – Barmar Mar 27 '17 at 15:20
  • Thanks for the help – Sir V Mar 27 '17 at 15:30
  • Possible duplicate of [Converting 'WITH CTE' MSSQL to MySQL](https://stackoverflow.com/questions/29113076/converting-with-cte-mssql-to-mysql) – Paul Sweatte Jul 06 '17 at 17:31

0 Answers0