I have the following query
select m.movementid, m.orderid, m.pickupdate, m.pickupnotes,
b.bin_size, b.bin_type,
l.address, l.suburb, l.postcode, l.state,
if(rs.run_action = 'Pick', if (r.run_state = 'Active' or r.run_state='Ready', 1, 0), 0) as active_on_pick
from bb_movement m
inner join bb_bins b on b.bin_id = m.bin_id
inner join bb_location l on l.locationid = m.locationid
inner join bb_runsheet rs on rs.movement_id = m.movementid
inner join bb_run r on r.run_id = rs.run_id
where m.mvtstate = 'Active'
order by m.locationid, m.pickupdate
which I want to produce a result where the active_on_pick column contains a 0 or 1 for each movementid. A record exists in the bb_runsheet table when a given movementid is added to a bb_run (a bb_run can have many bb_runsheet records, which primary contain a movementid)
The problem I have is that when a movement IS on a run (ie: has a bb_run record which matches the criteria and an entry in the bb_runsheet table) I get 2 rows in the result dataset - eg:
mvt_id active_on_pick
21 0
21 1
all I want is 21 and 1. I tried subqueries and other variants (such as group by movementid) but can seem to nail it. I'm using mysql