I have two columns: user_id and gift_id. I’m looking to return a result set where user_id = 15906 or where gift_id = 15906, but not where user_id = gift_id.
So out of the following data I should get two records.
user_id | gift_id
--------------------------
15906 | null
15906 | 15906
12345 | 15906
I want the first and last record of that set and not the one where user_id and gift_idmatch.
The problem with the above SQL statements is that they do not take into account that the SQL statement is comparing type int to type NULL… most sql parser don’t really like this.
Try xQbert’s code but using the coalesce function
This will make it so any NULL is converted to 0 for proper comparisions.