Reputation: 2266
there is feeds and likes tables, first i query data from feeds table then try to get likes for likes table for fetched feeds.
feeds table:
`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,
likes table:
like_id
like_userid
like_type
like_postid
now i want query form likes table such
IN((1, 'status'),(2,'image'),(3, 'status'))
// IN((like_postid,like_type),(like_postid,like_type),(like_postid,like_type))
example query:
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';
now i want rewrite top query with IN function
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?
Upvotes: 0
Views: 666
Reputation: 3168
this is one of the query to perform top N analysis check it
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
Upvotes: 1
Reputation: 1980
You can try this,
SELECT * FROM likes WHERE (like_postid, like_type) IN ((1,'status'),(2,'image'),(5,'status'));
Upvotes: 3