Working with combined expressions in WHERE clauses in Laravel 4

When retrieving records from tables in our database, you often have to write combined expressions in WHERE clauses like [sourcecode language=”sql”] SELECT * FROM users WHERE status=1 AND (fname = ‘John’ OR lname=’Doe’) [/sourcecode] The query above is pulling out all users who’s status is set to 1, and fname is equal to ‘John’ or … Continue reading Working with combined expressions in WHERE clauses in Laravel 4

Get a list of Top 10 authors in a WordPress blog, and sort them by firstname and last name

Getting top 10 authors’s list from WordPress is actually pretty simple with a SELECT query. Here is the SQL for that which sorts the list by number of posts of each authors [sourcecode language=”sql”] SELECT wp_users.id, display_name, user_login, user_nicename, count(wp_posts.id) AS number_of_posts FROM wp_users JOIN wp_posts ON wp_posts.post_author = wp_users.id GROUP BY wp_posts.post_author ORDER BY … Continue reading Get a list of Top 10 authors in a WordPress blog, and sort them by firstname and last name