mysql SELECT with IF statement
Hi i have easy function like this:
(25 is only random user id for example)
SELECT * FROM statuses WHERE user_id=4310
Works okay. To retrieve my statuses WHERE USER ID is MY(USER) ID... but now i need to make it more complex... i am working on "sharing statuses" with this DB...
Whats the best way to do it? I am pretty confused... i have in mind something like... select from DB where user id is my ... but if shared from is not null .. select instead status with id = shared from id... or i dont know .. something like that.
How would you do that? And yes i can modify the DB table little be if i need to add some helping column or something.
PERFORMANCES ARE ALSO IMPORTANT!
I am trying do something like:
FROM statuses AS st WHERE
IF(st.shared_from_id is null, st.user_id=4310, st.id=st.shared_from_id)
ORDER BY st.id DESC LIMIT 15
But it doesnt select the extra row i need.