...

Running SQL queries on a database with phpMyAdmin

Running SQL queries on a database with phpMyAdmin

phpMyAdmin is a powerful web-based tool that allows you to manage your MySQL or MariaDB databases. One of the key features of phpMyAdmin is the ability to run SQL queries directly on your database. This guide will walk you through the steps to run SQL queries using phpMyAdmin.

Steps to Run SQL Queries

  1. Access phpMyAdmin:

    Open your web browser and navigate to the phpMyAdmin URL. This is typically something like http://localhost/phpmyadmin if you are running it locally, or the specific URL provided by your web host.

  2. Log In:

    Log in to phpMyAdmin using your database username and password. This information is usually provided by your web hosting provider or set up during the installation of phpMyAdmin.

  3. Select the Database:

    Once logged in, you will see a list of databases on the left-hand side. Click on the database you want to run the SQL queries on.

  4. Open the SQL Tab:

    After selecting the database, click on the SQL tab at the top of the page. This will open the SQL query editor.

  5. Enter Your SQL Query:

    In the SQL query editor, type or paste the SQL query you want to run. For example, to select all records from a table named users, you would enter:

    SELECT * FROM users;
  6. Execute the Query:

    Click the Go button to execute the query. phpMyAdmin will run the query and display the results below the query editor.

Example: Running a SQL Query

Suppose you want to retrieve all records from the products table where the price is greater than 100. Follow these steps:

  1. Select the Database: Choose the database containing the products table.
  2. Open the SQL Tab: Click on the SQL tab at the top.
  3. Enter the SQL Query: In the SQL query editor, enter the following query:
  4. SELECT * FROM products WHERE price > 100;
  5. Execute the Query: Click Go to run the query. The results will be displayed below the query editor.

Common SQL Queries

  • Select All Records:
    SELECT * FROM table_name;
  • Insert a New Record:
    INSERT INTO table_name (column1, column2) VALUES ('value1', 'value2');
  • Update Existing Records:
    UPDATE table_name SET column1 = 'value1' WHERE condition;
  • Delete Records:
    DELETE FROM table_name WHERE condition;

Conclusion

Running SQL queries using phpMyAdmin is a straightforward process that allows you to interact with your database directly. By following the steps outlined in this guide, you can efficiently execute queries to manage and retrieve data from your database.

This tutorial assumes you’ve already logged in to phpMyAdmin

Now let’s learn how to run SQL queries on a database

Click the database table you wish to run a SQL query on
phpMyAdmin

As demonstrated in another tutorial, you can delete (or drop) a field from a table by selecting it here then clicking the drop icon here
phpMyAdmin Cloud
In this tutorial however, let’s demonstrate how to delete this address field using pure SQL commands

Click the SQL button here
phpMyAdmin Web hosting

Then type the SQL command to delete the address field from the details table. Click Go when finished
phpMyAdmin Hosting
That’s it! the SQL command has been executed. Let’s go take a look

The address field is no longer in our details table
phpMyAdmin Cloud Hosting
You can also click the SQL button directly from the table view (instead of from the database view which is what we did)…..

….. doing so presents a SQL query window that is partially filled in
phpMyAdmin
For more information on learning about SQL query syntax, visit the MySQL documentation available here

This is the end of the tutorial. You now know how to run SQL queries on a database using phpMyAdmin

Previous Post
Modifying fields in database tables with phpMyAdmin
Next Post
Renaming database tables with phpMyAdmin