I have query like this:
mysql> SELECT
-> ir.id, ir.no_surat, link.condition_id
-> FROM inspection_report ir
->
-> LEFT JOIN link_item_condition_ir_to_ir link
-> ON link.inspection_id = ir.id
->
-> WHERE ir.no_surat LIKE '%E67%'
-> ORDER BY ir.no_surat ASC, link.condition_id DESC;
+------+---------------+--------------+
| id | no_surat | condition_id |
+------+---------------+--------------+
| 7561 | E6779/10/2018 | 1 |
| 7562 | E6780/10/2018 | 5 |
| 7562 | E6780/10/2018 | 1 |
| 7563 | E6781/10/2018 | 5 |
| 7563 | E6781/10/2018 | 1 |
+------+---------------+--------------+
5 rows in set (0.03 sec)
Please see in no_surat column.
There is 3 unique no_surat. My Goal is: just select the data that not have condition_id = 5.
I also already try this,
mysql> SELECT
-> ir.id, ir.no_surat, link.condition_id
-> FROM inspection_report ir
->
-> LEFT JOIN link_item_condition_ir_to_ir link
-> ON link.inspection_id = ir.id
->
-> WHERE ir.no_surat LIKE '%E67%'
-> AND
-> condition_id != 5
->
-> ORDER BY ir.no_surat ASC, link.condition_id DESC;
+------+---------------+--------------+
| id | no_surat | condition_id |
+------+---------------+--------------+
| 7561 | E6779/10/2018 | 1 |
| 7562 | E6780/10/2018 | 1 |
| 7563 | E6781/10/2018 | 1 |
+------+---------------+--------------+
3 rows in set (0.02 sec)
But still not work, Please advise.
The result that I expected is, Ignoere all 'no_surat' columnt that have condition_id = 5
+------+---------------+--------------+
| id | no_surat | condition_id |
+------+---------------+--------------+
| 7561 | E6779/10/2018 | 1 |
+------+---------------+--------------+
Thanks
How about this query:
mysql> SELECT
-> ir.id, ir.no_surat, link.condition_id
-> FROM inspection_report ir
->
-> LEFT JOIN link_item_condition_ir_to_ir link
-> ON link.inspection_id = ir.id
->
-> WHERE ir.no_surat LIKE '%E67%'
-> GROUP BY ir.id
->
-> HAVING GROUP_CONCAT( link.condition_id ) NOT LIKE "%5%";
+------+---------------+--------------+
| id | no_surat | condition_id |
+------+---------------+--------------+
| 7561 | E6779/10/2018 | 1 |
+------+---------------+--------------+
1 row in set (0.00 sec)
It looks good ?
Here is the fiddle : sqlfiddle