How to use alias in where clause in mysql

后端 未结 4 1739
不思量自难忘°
不思量自难忘° 2021-01-13 04:16

Are there any other way of doing this query:

SELECT CONCAT_WS(\" \", strLname, strFname, strMname) AS lessor_name 
FROM tbl_lessor 
WHERE lessor = \'$less         


        
相关标签:
4条回答
  • 2021-01-13 04:34

    In MySQL, you cannot use the alias near WHERE.

    0 讨论(0)
  • 2021-01-13 04:41

    This will work.

    SELECT * FROM (SELECT CONCAT_WS(" ", strLname, strFname, strMname) AS lessor_name 
    FROM tbl_lessor) AS t1 
    WHERE lessor_name = '$lessor_name'
    
    0 讨论(0)
  • 2021-01-13 04:48

    It might be due to lessor instead of lessor_name in where clause. So try with below once :

    SELECT CONCAT_WS(" ", strLname, strFname, strMname) AS lessor_name 
    FROM tbl_lessor 
    having lessor_name= '$lessor_name'
    
    0 讨论(0)
  • 2021-01-13 04:56

    maybe this will work:

    SELECT CONCAT_WS(" ", strLname, strFname, strMname) AS lessor_name  
    FROM tbl_lessor  
    WHERE CONCAT_WS(" ", strLname, strFname, strMname) = '$lessor_name' 
    
    0 讨论(0)
提交回复
热议问题