SELECT * FROM friends
WHERE (user1 = $userid OR user2 = $userid) AND accepted = 1
如果我想从表“users”中获取 user2 的信息,JOIN 会是什么样子?
table friends:
`id` int(11) NOT NULL auto_increment,
`user1` int(11) NOT NULL,
`user2` int(11) NOT NULL,
`date` datetime NOT NULL,
`accept` tinyint(1) NOT NULL,
`type` varchar(32) NOT NULL
users:
`id` mediumint(8) NOT NULL auto_increment,
`username` varchar(32) NOT NULL,
`password` varchar(40) NOT NULL