i want to select records contain given ID and given Branch so i came up with this query and i want to know whether this is the correct way to write this
im using codeigniter
$orderids = array('2', '3');
$branch = array('branch1', 'branch2');
$this->db->where_in('order_id', $orderids);
$this->db->where_in('branch', $branch);
$query = $this->db->get('tbl_order_data');
this makes the query
SELECT *
FROM (`tbl_m_order_collection_data`)
WHERE `order_id` IN ('2', '3')
AND `branch` IN ('branch1', 'branch2')
my table looks like
+----+----------+-------------+-----------+
| ID | order_id | branch | item_code |
+----+----------+-------------+-----------+
| 1 | 1 | branch1 | 4R1 |
| 2 | 1 | branch2 | 4R11 |
| 3 | 1 | branch2 | ACS20x20 |
| 4 | *2 | branch1 | ACS20x27 |
| 5 | *2 | branch1 | ACS20x20 |
| 6 | 1 | branch1 | ACS20x20 |
| 7 | 2 | branch2 | ACS20x27 |
| 8 | *3 | branch2 | ACS20x20 |
+----+----------+-------------+-----------+
what im trying is to get star marked records from table. so the above query is valid for use?
INclauses are independent of one another.SELECT * FROM table WHERE (order_id = 2 AND branch = 'branch1') OR (order_id = 3 AND branch = 'branch2')(that would only give you the 3 rows you starred)?