Skip to main content
phpMyAdmin Guide
CHAPTER 07 Beginner

How to Run SQL Queries in phpMyAdmin | SQL Execution

Updated: May 16, 2026
15 min read

# CHAPTER 7

Running SQL Queries in phpMyAdmin

1. Introduction

The visual buttons in phpMyAdmin are fantastic for simple tasks. However, real-world database administration requires complex logic. If your boss says, *"Give me a list of all customers from New York who bought a laptop in the last 30 days,"* there is no button for that. You must speak directly to the database engine. You must write raw SQL (Structured Query Language). In this chapter, we will learn how to use phpMyAdmin's built-in SQL Editor to execute powerful, custom commands.

2. Learning Objectives

By the end of this chapter, you will be able to:
  • Access and utilize the SQL tab.
  • Write and execute custom SELECT queries.
  • Execute destructive UPDATE and DELETE queries.
  • Utilize the query formatting and auto-complete features.
  • Access your Query History to recover previous commands.

3. The SQL Tab Editor

To access the command center:
  1. 1. Click your database in the left sidebar (e.g., company_db).
  1. 2. Click the SQL tab at the top of the screen.
  1. 3. You are presented with a large, blank text box. This is the Query Editor.

Features of the Editor:

  • Syntax Highlighting: As you type, SQL keywords (like SELECT) turn purple or blue, while text strings turn green. This helps you spot typos instantly.
  • Auto-Complete: If you type USE, a dropdown will appear suggesting users. Press Tab to autocomplete the table name!
  • Clear & Format: Below the text box, there are buttons to "Clear" the box, or "Format" your messy code into beautiful, readable, indented SQL.

4. Running a SELECT Query

Let's ask the database a question.
  1. 1. In the SQL Editor, type:
sql
123
SELECT first_name, email 
FROM users 
WHERE status = 'Active';
  1. 2. Click the Go button in the bottom right corner.
  1. 3. phpMyAdmin sends the query to the server. The screen refreshes, and you are presented with a custom visual grid showing *only* the first names and emails of active users!

5. Running an UPDATE Query

Imagine 500 users registered with @oldcompany.com, and you need to change all 500 of them to @newcompany.com. Doing this manually in the Browse tab would take hours. With SQL, it takes 1 millisecond.
  1. 1. Open the SQL tab.
  1. 2. Type the update command:
sql
12
UPDATE users 
SET email = REPLACE(email, '@oldcompany.com', '@newcompany.com');
  1. 3. Click Go.
  1. 4. phpMyAdmin will flash a green box saying: *"500 rows affected."* You just saved hours of manual labor!

6. Running a DELETE Query

WARNING: Running raw DELETE queries is the most dangerous thing a DBA can do. If you type DELETE FROM users; and click Go, the database will instantly vaporize every single user in the table.

Always use a WHERE clause!

sql
123
-- Safe deletion
DELETE FROM users 
WHERE last_login < &#039;2020-01-01';

*Safety Feature:* If you try to run an UPDATE or DELETE query without a WHERE clause, phpMyAdmin will throw a pop-up warning asking if you are absolutely sure you want to destroy the entire table. Never ignore this warning!

7. The Console and Query History

What if you wrote a brilliant, complex 10-line SQL query yesterday, but you forgot to save it in a text document?
  1. 1. Look at the very bottom of the phpMyAdmin screen. You will see a small tab labeled Console.
  1. 2. Click it. A panel slides up from the bottom of the screen.
  1. 3. Click the History tab inside the console.
  1. 4. You will see a list of every single SQL query you have executed recently! You can click any query to instantly load it back into the editor.

8. Mini Project: The Analyst Workflow

Scenario: The marketing team needs a list of the 5 most expensive products in the Electronics category, sorted by price.
  1. 1. Go to the SQL tab.
  1. 2. Formulate the logic:
sql
12345
SELECT product_name, price 
FROM products 
WHERE category = &#039;Electronics' 
ORDER BY price DESC 
LIMIT 5;
  1. 3. Click Go.
  1. 4. When the visual grid appears, scroll to the bottom of the page. Click the Export button to download these specific 5 rows as a CSV file to email to the marketing team.

9. Common Mistakes

  • Forgetting the Semicolon: If you want to run multiple queries at the exact same time in the SQL box, you MUST separate them with a semicolon ;.
sql
12
UPDATE users SET status = &#039;Active' WHERE id = 1;
UPDATE users SET status = &#039;Banned' WHERE id = 2;

If you forget the semicolon, MySQL will think it is one giant, confusing sentence and throw a syntax error.

10. Best Practices

  • Test with SELECT before UPDATE: Before running a massive UPDATE or DELETE query, write it as a SELECT query first!
e.g., SELECT * FROM users WHERE status = 'spam';. View the results. If it looks correct, *then* change the word SELECT * to DELETE and run it again. This prevents catastrophic accidents.

11. Exercises

  1. 1. What built-in feature of the phpMyAdmin SQL editor suggests table and column names as you type?
  1. 2. Where can you find a log of previous SQL commands you executed?

12. Database Challenges

You need to delete a user with id = 99. You type DELETE * FROM users WHERE id = 99; into the SQL tab and click Go. phpMyAdmin throws a syntax error. What is wrong with your SQL syntax? *(Answer: The * symbol is used in SELECT queries to mean "all columns". It is invalid in a DELETE query because you delete entire rows, not specific columns. The correct syntax is DELETE FROM users WHERE id = 99;)*

13. MCQ Quiz with Answers

Question 1

When utilizing the SQL tab in phpMyAdmin, what is the primary purpose of the "Format" button located beneath the text editor?

Question 2

A Database Administrator is about to execute a complex DELETE query to purge millions of old records. What is the universally recommended best practice to ensure the WHERE clause logic is correct before executing the destructive command?

14. Interview Questions

  • Q: Discuss the architectural integration of the SQL Tab within phpMyAdmin. When a user writes a raw query and clicks "Go", explain the pathway the query takes from the web browser to the MySQL engine and back to the visual grid.
  • Q: Explain the purpose of the phpMyAdmin "Console" panel located at the bottom of the interface. How does it assist developers in their daily workflows?

15. FAQs

Q: I clicked "Go" on a query, and the page has been loading for 2 minutes. What is happening? A: Your query is likely trapped in an infinite loop or performing a massive Full Table Scan on a huge database. If it takes too long, PHP will eventually hit a "Max Execution Time" limit and kill the query automatically to save the server from crashing.

16. Summary

You have unlocked the true power of the database. By utilizing the SQL tab, leveraging syntax highlighting, accessing your command history, and safely testing destructive queries, you are no longer limited by graphical buttons. You can command the database engine with absolute precision.

17. Next Chapter Recommendation

We can create tables and manipulate data effortlessly. But what happens when we finish building our app locally, and it is time to move the database to a live production server on the internet? In Chapter 8: Importing and Exporting Databases, we will master the art of data migration.

Finish this Chapter

Save your progress on your learning path and prepare for coding interview challenges.

Discussion

Join the discussion

Log in or create a free account to participate.

Sort: ·