I’ve looked around for a while, and I’m not really sure whether I need some sort of IF statement, LIMIT statement, or something completely different.
SITUATION
I have a database that looks something like this:
id | elem_id | elem_data | draft
1 | uniq1234 | examplestr | 0
2 | uniq1653 | examplestr | 1
3 | uniq9964 | examplestr | 0
4 | uniq1234 | examplestr | 1
And so on and so forth…
My Intent
I want to select only one row for every unique elem_id. Where two exist, I want to select the one that has a draft value of 1. (So, for a query on the above table it would find two occurrences of the elem_id uniq1234 and select the one with the draft value of 1 (that is, row 4)).
1 Answer