In my database has two tables to store my campaigns details.
I want to get the best campaign which one was the most participating users and well as ignore trashing records or campaigns. How can i write a code to get a result like this?
You should have to filter trash records of campaign_records and campaigns tables in very first time by using status column. Then order by id column counting with descending order. now you can get campaigns with max to minimum users participation order. finally you can group by campaign_id. Then you can get best campaign
Try this mysql statement.
SELECT campaign_id FROM campaign_records WHERE campaign_id IN ( SELECT id FROM campaigns WHERE status != '0' ) AND status != '0' GROUP BY campaign_id ORDER BY COUNT(id) DESC LIMIT 1;
Try this code to get campaign detail.
SELECT * FROM campaigns as c JOIN campaign_records as r ON c.id = r.campaign_id WHERE r.status != '0' AND c.status != '0' GROUP BY r.campaign_id ORDER BY COUNT(r.id) DESC LIMIT 1;
SELECT user_id,COUNT(id) as campaigns FROM campaign_records WHERE campaign_id IN ( SELECT id FROM campaigns WHERE status != '0' ) AND status != '0' GROUP BY user_id ORDER BY COUNT(id) DESC LIMIT 1;
Who get fresh code scripts from codrate!
Will send your codrate site configuration email in your mail account.
codrate.com is a standard, fast cross browsing and highly versatile site. It is useful for many large number of Program Development Industries. So you can get support form Codrators , who are the codrate's joiners around world to help your program developments, You can answer other codrator's questions. Communicate with them. Share your knowledge with them. Do you have an interest in programming, So publish your articles about programming. It will help to maintain your professional co-profile. Actually codrate.com is not such as a regular web site. It will be gave new experience, best narrow cross-browser view, reduce processing time to receive browsing request, it's mean do not wasting your time to browsing codrate's web pages because it has been upgrade always modern coding ways. So, what do you waiting for ?. Try your own.