sql - Select 2 time records from one table -
i have 2 table below
postlist: post_id(pk,identity)  likelist: like_id(pk,identity), post_id(fk)   every entry of post in likelist, liked.
this task post on facebook
i passing 2 value .cs, when datalist binding whichever post_id , current user id(mid)
- count every post like.
 - if current user alredy liked, change button text unlike
 
i create query like,
select mid ,(select count(post_id) likelist post_id=@sp_post_id) like_count likelist (post_id=@sp_post_id , mid=@sp_mid)  group mid   i got post_id count in below case if past post_id=27 ,  user/mid=2  not found record.
what want: check post likes count , check if user post or not. (how check counts , current user or not?)
table data:
postlist
post_id fid   mid   post_img         post_msg                      post_time  1       1     1     tulips.jpg       post user1.         2015-05-26 3       3     2     lighthouse.jpg   post user2.         2015-05-26 5       1002  3     road1.jpg        post user3.         2015-05-26 6       3     2     map1.jpg         2 post user2.       2015-05-27 7       1     1                      text post user1  2015-05-27 26      1     1     globe.jpg                                      2015-05-28 27      1003  5     gujarat.jpg      post user5, again.  2015-05-29 30      3     2     location2.jpg    post user2               2015-05-29   likelist
like_id  post_id    mid like_status like_time 1        27         1   1           2015-05-29 2        30         1   1           2015-05-29 3        6          1   1           2015-05-29 4        30         2   1           2015-05-29 9        6          2   1           2015-05-29   what happen: when user online: mid=1
post_id:30 likes 2 times (online user too)
when user online: mid=2
post_id:27 likes 1 time (online user not it)
select      post_id,      count(*) likecount,     max(case mid when @sp_mid 1 else 0 end) userliked -- 0 no; 1 yes likelist  1 = 1     , post_id = @sp_post_id -- can comment line viewing post     , like_status = 1 group post_id      
Comments
Post a Comment