Title: Sql query to get all users
Last modified: August 20, 2016

---

# Sql query to get all users

 *  [nonname](https://wordpress.org/support/users/bipies/)
 * (@bipies)
 * [14 years, 9 months ago](https://wordpress.org/support/topic/sql-query-to-get-all-users/)
 * Hi:
 * I’m using this sql query to get all users:
 *     ```
       $excluded = '1,29,24';
       $sql = 'SELECT distinct post_author FROM '.$wpdb->posts. " WHERE post_author NOT IN ($excluded) ORDER BY rand()";
       $authors = $wpdb->get_results($sql)
       ```
   
 * ;
 * But whe executed always appear a repeated user with wrong “latest post” and don’t
   know why, any idea?
 * Thanks!

The topic ‘Sql query to get all users’ is closed to new replies.

## Tags

 * [query](https://wordpress.org/support/topic-tag/query/)
 * [sql](https://wordpress.org/support/topic-tag/sql/)
 * [users](https://wordpress.org/support/topic-tag/users/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 0 replies
 * 1 participant
 * Last reply from: [nonname](https://wordpress.org/support/users/bipies/)
 * Last activity: [14 years, 9 months ago](https://wordpress.org/support/topic/sql-query-to-get-all-users/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
