Is it possible to select from an alias in mysql?

前端 未结 2 370
清歌不尽
清歌不尽 2021-01-27 07:02

I created a table alias named tbl, and I want to select from that. But I am unable to do this. I know that my code is not correct nor optimized, but I am simply tes

2条回答
  •  闹比i
    闹比i (楼主)
    2021-01-27 07:49

    You have that error because there's no physical table involved in the query, because tbl is just the alias you created. If you want just to test if your username exists, execute this query:

    SELECT CASE
    WHEN id = 1 THEN 'Username Exists' ELSE 'Username does not exist'
    END
    FROM (SELECT 1 AS id, 'bob' AS username, 'pass' AS password) AS tbl
    

提交回复
热议问题