用union語句時報錯Every derived table must have its own alias

字號+ 編輯: 国内TP粉 修訂: 种花家 來源: 2024-01-18 我要說兩句(0)

使用union遇到的常見錯誤之一。

错误复现

先写一个这样的语句在测试环境下运行:

SELECT some_field1 FROM (
    SELECT some_field1 from some_table where cond = 1
    union all
    SELECT some_field1 from some_table where cond = 888
) LIMIT 0, 50;

就会报上述故障Every derived table must have its own alias, 中文意思是少了个表别名, 加上就OK, 改成以下:

SELECT some_field1 FROM (
    SELECT some_field1 from some_table where cond = 1
    union all
    SELECT some_field1 from some_table where cond = 888
) tbl LIMIT 0, 50;

完结撒花

閲完此文,您的感想如何?
  • 有用

    1

  • 沒用

    0

  • 開心

    0

  • 憤怒

    0

  • 可憐

    0

1.如文章侵犯了您的版權,請發郵件通知本站,該文章將在24小時内刪除;
2.本站標注原創的文章,轉發時煩請注明來源;
3.交流群: PHP+JS聊天群

相關課文
  • [InnoDB] Failed to set NUMA memory policy of buffer pool page frames

  • 讓Mysql查詢後直接返回json字符串的方法

  • postgresql的pg_dump備份簡單方法

  • 使用sql語句在MySQL庫中去掉字段左邊、右邊指定字符串

我要說說
網上賓友點評