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.

share|improve this question
    
It helps if we can see what you are showing us – RiggsFolly Dec 8 '16 at 19:10
    
WHAT are you trying to do? Using boolean expressions as CONCAT() arguments is highly non-intuitive. – Gordon Linoff Dec 8 '16 at 19:14
    
WARNING: This has some severe SQL injection bugs because $_GET data is used inside the query. Whenever possible use prepared statements. These are quite straightforward to do in mysqli and PDO where any user-supplied data is specified with a ? or :name indicator that’s later populated using bind_param or execute depending on which one you’re using. NEVER put $_POST or $_GET data directly in your query. – tadman Dec 8 '16 at 19:16
    
@RiggsFolly Pardon me, but I think that the question is clear enough to understand. – M Ansyori Dec 8 '16 at 19:17
1  
@AlexandreT Yes correct. My bad, I didn't know using '= NULL' and 'IS NULL' are making any difference. – M Ansyori Dec 9 '16 at 1:55
up vote 4 down vote accepted

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";
share|improve this answer
    
Thanks. I didn't know using '= NULL' and 'IS NULL' are making any difference. The query works, result is good as I expected, will accept this as an answer in 10 mins. Stackoverflow rule. peace – M Ansyori Dec 8 '16 at 19:14

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.