Title: SQL Query
Last modified: August 19, 2016

---

# SQL Query

 *  [shaf](https://wordpress.org/support/users/shaf/)
 * (@shaf)
 * [17 years, 9 months ago](https://wordpress.org/support/topic/sql-query-2/)
 * Hi
 * I am using the $wpdb to carry out SQL queries. I am trying to write a query that
   will allow me to see all the tables in the database but I keep getting an unknown
   database error. See code below:
 *     ```
       $sql  = "SHOW TABLES FROM " . '$wpdb';
       if (!$result = mysql_query($sql))
       {
       	die ('Error getting table list (' . $sql . ' :: ' . mysql_error() . ')');
       }
       ```
   

Viewing 1 replies (of 1 total)

 *  [slars](https://wordpress.org/support/users/slars/)
 * (@slars)
 * [17 years, 9 months ago](https://wordpress.org/support/topic/sql-query-2/#post-790674)
 * Shaf,
 * Try this query instead:
 * $sql = “SHOW TABLES”;
 * Your connect string should already connect you to the MySQL DB and you should
   have a database string which defines which database to act upon. “SHOW TABLES”
   is a basic sql statement to show all tables in your current database.
 * Steve

Viewing 1 replies (of 1 total)

The topic ‘SQL Query’ is closed to new replies.

## Tags

 * [SQL queries](https://wordpress.org/support/topic-tag/sql-queries/)
 * [wpdb](https://wordpress.org/support/topic-tag/wpdb/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 2 participants
 * Last reply from: [slars](https://wordpress.org/support/users/slars/)
 * Last activity: [17 years, 9 months ago](https://wordpress.org/support/topic/sql-query-2/#post-790674)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
