something like the following is what I’m looking to do
SELECT id, status, Gid, Uid, note FROM notes LIMIT 10
but the status id could be different and it would need to be something like the following
SELECT a.id, a.status, a.Gid, a.Uid, a.note
FROM notes as a
WHERE
IF(a.status < 2, DONT SELECT),
IF(a.status == 2,
(SELECT approved FROM friends WHERE Uid = a.Uid AND Fid = ".$_SESSION['Uid'].")
IF(approved = 1, SELECT ROW, else DONT)
)
IF(a.status == 3, SELECT)
IF(a.status == 4,
(SELECT Gid FROM friends WHERE Uid = a.Uid AND Fid = ".$_SESSION['Uid'].")
IF(Gid == a.Gid, SELECT ROW, else DONT)
ORDER BY id DESC
LIMIT 10
I looked up the CASE command, but not sure how to use that, but I can see that being the way to do it, but yeah.. I’m not sure how to.
The above is an example of what I’m trying to do, the a.Uid can be different ids, so when the status == 2 or 4 we need to see if the viewing user is an approved friend or within the groupId (Gid)
any help fixing this query would be much appreciated.. I could change the notes table up a little if need be as its not in production yet, but is discouraged. I’m open to suggestions though
Thanks in advance!
I think this will do what you want: