0

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?
3
  • uhmm the question is slightly unclear, what do you mean by two conditions? can you give example? Commented Jan 11, 2013 at 5:57
  • Try to provide some sample rows and your expected output from a good query. Commented Jan 11, 2013 at 5:58
  • example records with desired result can help us understand your question better :D Commented Jan 11, 2013 at 6:05

2 Answers 2

3

You can try this,

SELECT * FROM likes WHERE (like_postid, like_type) IN ((1,'status'),(2,'image'),(5,'status'));
Sign up to request clarification or add additional context in comments.

Comments

1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.