mysql - 查询错误 (1248) : Every derived table must have its own alias INNER JOIN

标签 mysql inner-join alias

我想在 2 个表上使用 INNER JOIN,但是当我尝试以下任一语句时,我得到

Error in query (1248): Every derived table must have its own alias

SELECT DISTINCT(t2.col)
FROM tab2 as t2
INNER JOIN (
  SELECT DISTINCT(t1.col)
  FROM tab1 as t1
  WHERE t1.id>678 AND t1.id<5248
) ON t2.col=t1.col
WHERE t2.id>10 AND t2.id<3770

SELECT DISTINCT(col)
FROM tab2 as t2
INNER JOIN (
  SELECT DISTINCT(col)
  FROM tab1 as t1
  WHERE t1.id>678 AND t1.id<5248
) ON t2.col=t1.col
WHERE t2.id>10 AND t2.id<3770

有什么问题吗?

最佳答案

您需要向连接表添加别名:

SELECT DISTINCT(t2.col) FROM tab2 as t2 INNER JOIN (SELECT DISTINCT(t1.col) FROM tab1 as t1 WHERE t1.id>678 AND t1.id<5248) as t3 ON t2.col=t3.col WHERE t2.id>10 AND t2.id<3770

关于mysql - 查询错误 (1248) : Every derived table must have its own alias INNER JOIN,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38695715/

相关文章:

php - Mysql 使用 Like 运算符在 json 数组中搜索

MySql 返回的是列名,而不是值

mySQL 内连接表(如果需要)

sqlite - 在 sqlite3 where 子句中使用列别名

c++ - 有没有办法将 cpp 11 中的别名 std::make_pair 函数键入到 abc::make_pair?

php - PHP错误:您的SQL语法有错误。

php - 循环遍历二维 session 数组购物车php

sql - 错误: 'duplicate key value violates unique constraint' even when checking with 'where not in'

mysql ->、<、<>、= 内部连接条件的运算符

mysql - MySQL 中的 SHOW COLUMNS 别名