I am trying to choose the row where
1)list.ispublic = 1
2)userlist.userid='aaa' AND userlist.listid=list.listid
I need 1)+2)
There is a row already but this statement can not get that row, is there any problem?
List table:
ListID ListName Creator IsRemindSub IsRemindUnSub IsPublic CreateDate LastModified Reminder
1 test2 aaa 0 0 1 2012-03-09 NULL NULL
user_list table (No row):
UserID ListID UserRights
My test version
SELECT *
FROM list l
INNER JOIN user_list ul ON ul.ListID = l.ListID
WHERE l.IsPublic = 1 AND ul.UserID = '09185346d'
This is the Result when there are two list in user_list has aaa , and one list is public in list, so will this cause double retrieve of that one public list in list if i get it in php ?
ListID ListName Creator IsRemindSub IsRemindUnSub IsPublic CreateDate LastModified Reminder UserID ListID UserRights
1 test2 aaa 0 0 1 2012-03-09 NULL aaa 1 read
2 t2 aaa 0 0 1 2012-03-09 NULL aaa 2 read
First, try to only
SELECTthe fields you actually need. Second, write yourJOINSexplicitly – it helps readability. For example:Incidentally, if you have no data in your
user_listtable, then you have no way to meet the requirements you have set. If as you put it “userlist.listid=list.listid” is necessary and theuser_listtable is empty, you will always get zero rows returned.Edit: And no, it won’t cause rows to be retrieved double. Whatever results you get with your SQL query will be the same results you get in a PHP script – the mechanism for retrieving the data is the same.