mysql - Add ratings from two different tables and use post id to get data from third table -


i making rating system in there 2 ways add ratings.

1 - when user likes or unlikes (for use 1 , 0 unlike , store in db reference in field rating).

2 - when admin wants add bulk rating or unlike post admin.

we have 2 different tables. table in user data being stored storing 1 user record @ time 1 ip. means unique ip user can or unlike post once.

the table name storing user end data ai_rf_ratings , table storing admin data ai_rf_bulk_ratings.

now wanted make query can best post, means results expecting should ordered number of ratings on post. need first add ratings given various users post in ai_rf_ratings table made query , works fine

select count(*) total_ratings,main_id ai_rf_ratings type='0' group main_id 

since there multiple records 1 post , multiple users used count. in admin table ai_rf_bulk_ratings there 1 record 1 post , storing bulk rating on post using field count. if adding 2 main_id represents post_id in both table final count should total_ratings above query plus value in count field on ai_rf_bulk_ratings table. wanted use third table post table post data ordered post counts. possible or need make 2 queries ?

sql fiddle database

http://sqlfiddle.com/#!9/8093bb/1


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -