0

有提要和点赞表,首先我从提要表中查询数据,然后尝试为获取提要的点赞表获取点赞。

饲料表:

`feed_id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
`feed_postid` INT(15) UNSIGNED NOT NULL,
`feed_type` VARCHAR(40) NOT NULL,
`feed_userid` INT(12) UNSIGNED NOT NULL,
`feed_privacy` TINYINT(1) UNSIGNED NOT NULL,
`feed_uids` TEXT NULL,
`feed_title` VARCHAR(180) NULL DEFAULT NULL,
`feed_content` TEXT NOT NULL,
`feed_dateline` DATETIME NOT NULL,

喜欢表:

like_id
like_userid
like_type
like_postid

现在我想要查询表格喜欢这样的表格

IN((1, 'status'),(2,'image'),(3, 'status'))
// IN((like_postid,like_type),(like_postid,like_type),(like_postid,like_type))

示例查询:

SELECT * FROM likes WHERE like_postid = 1 AND like_type = 'status' OR like_postid = 2 AND like_type = 'image' OR like_postid = 5 AND like_type = 'status';

现在我想用 IN 函数重写顶部查询

SELECT * FROM likes WHERE like_postid, like_type IN((1,'status'), (2,'image'), (5, 'status')); --but this is not work, there is any way to do this?
4

2 回答 2

3

你可以试试这个

SELECT * FROM likes WHERE (like_postid, like_type) IN ((1,'status'),(2,'image'),(5,'status'));
于 2013-01-11T06:13:41.533 回答
1

这是执行前 N 个分析的查询之一 检查它

SELECT * FROM likes WHERE like_type in ('status','image') order by like_postid limit 2 union all SELECT * FROM likes WHERE like_type in ('status','image') order by like_postid offset 4 limit 1

于 2013-01-11T06:36:19.740 回答