简体   繁体   中英

PHP/MYSQL: Using 'CONCAT' and 'AND' clause in MYSQL Query

I'm trying to execute this query:

Query 1:

$query = "SELECT a.*, b.title_wo 
          FROM `worksheet_master` AS a 
            INNER JOIN `work_order` AS b ON a.wo_number = b.wo_number 
          WHERE CONCAT (a.`wo_number` like '" . $_POST["keyword"] . "%', 
                        `title_wo` like '" . $_POST["keyword"] . "%') 
          ORDER BY a.`wo_number` DESC LIMIT 0,50";

Query 2:

$query = "SELECT a.*, b.title_wo 
          FROM `worksheet_master` AS a 
            INNER JOIN `work_order` AS b ON a.wo_number = b.wo_number 
          WHERE CONCAT (a.`wo_number` like '" . $_POST["keyword"] . "%', 
                        `title_wo` like '" . $_POST["keyword"] . "%') 
            AND a.`status` = 'NULL' 
          ORDER BY a.`wo_number` DESC 
          LIMIT 0,50";

The Query 2 didn't gave me any result with AND clause while the Query 1 gave me the result.

Can anyone help me with this? I need to sort out the result which has the empty status in my table, that's why I added AND clause in Query 2 hoping the result will be as expected, but it's not.

Thank You.

Unless NULL is an actual string, you need to use IS NULL instead.

$query = "SELECT a.*, b.title_wo 
      FROM `worksheet_master` AS a 
        INNER JOIN `work_order` AS b ON a.wo_number = b.wo_number 
      WHERE CONCAT (a.`wo_number` like '" . $_POST["keyword"] . "%', 
                    `title_wo` like '" . $_POST["keyword"] . "%') 
        AND a.`status` IS NULL 
      ORDER BY a.`wo_number` DESC 
      LIMIT 0,50";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM