How To Display Table In Sql

6 min read

Displaying a table in SQL is one of the first practical skills every database learner needs. The phrase display table in SQL can mean two different things: showing the data inside a table with a SELECT query, or showing the table’s structure with commands such as DESCRIBE, SHOW COLUMNS, or INFORMATION_SCHEMA. Also, whether you want to see the rows stored inside a table, inspect its columns and data types, or list every table in a database, SQL gives you clear commands for each task. Understanding both meanings will make you far more comfortable working with real databases That's the part that actually makes a difference. Which is the point..

What Does “Display Table in SQL” Mean?

In everyday SQL practice, “display table” usually refers to retrieving the contents of a table so you can read the rows and columns. That is done with the SELECT statement, which is the foundation of almost every SQL query. A second, equally important meaning is displaying the table definition—its schema—so you can see column names, data types, constraints, and defaults Worth keeping that in mind..

Think of it this way:

  • Display table data means viewing the records stored in the table.
  • Display table structure means viewing how the table is built.
  • Display table list means viewing which tables exist in a database.

Each task uses a different SQL command, and each is useful in daily development, reporting, debugging, and data analysis.

Display Table Data with SELECT

The most common way to display table data in SQL is the SELECT statement. The basic syntax is simple:

SELECT column1, column2
FROM table_name;

If you want to display every column and every row, use the asterisk wildcard:

SELECT * FROM employees;

This query returns a result set containing all rows from the employees table. The asterisk is convenient for quick exploration, but it is not always the best choice in production queries. Selecting only the columns you need is clearer, faster, and less likely to break when the table structure changes Simple, but easy to overlook..

Choose Specific Columns

Instead of displaying the entire table, you can display only the columns that matter:

SELECT first_name, last_name, department
FROM employees;

This approach is especially useful when a table has dozens of columns. It keeps the output readable and reduces the amount of data transferred from the database.

Filter Rows with WHERE

To display only certain rows, add a WHERE clause:

SELECT first_name, last_name, salary
FROM employees
WHERE department = 'Sales';

The WHERE clause acts as a filter. You can combine conditions with AND, OR, and NOT, and you can use comparison operators such as =, >, <, >=, <=, and <>. For example:

SELECT *
FROM

employees
WHERE salary > 50000;

This returns only the rows where the salary column is greater than 50,000. You can combine conditions to narrow the output further:

SELECT first_name, last_name, salary
FROM employees
WHERE department = 'Sales' AND salary > 60000;

Sort Results with ORDER BY

Raw result sets are rarely useful in a random order. Add ORDER BY to sort the output:

SELECT first_name, last_name, salary
FROM employees
ORDER BY salary DESC;

Use DESC for descending order and ASC (the default) for ascending order. You can also sort by multiple columns, such as ORDER BY department ASC, salary DESC.

Limit the Number of Rows

Large tables can return thousands of rows. To display only a sample, use LIMIT in MySQL, PostgreSQL, and SQLite:

SELECT * FROM employees
LIMIT 10;

SQL Server uses TOP instead (SELECT TOP 10 * FROM employees;), while standard SQL uses FETCH FIRST 10 ROWS ONLY.

Display Table Structure

To see how a table is built rather than what it

contains, you need commands that describe the table itself. These are invaluable when you inherit a database or return to a project after some time.

Describe a Table

Most database systems provide a quick way to view a table's columns and their data types:

DESCRIBE employees;

MySQL and Oracle support DESCRIBE (or its shorthand DESC). PostgreSQL and SQLite use a slightly different approach:

-- PostgreSQL
\d employees

-- SQLite
PRAGMA table_info(employees);

The output lists each column name, its data type, whether it allows NULL values, and any keys or default values. This is the fastest way to confirm what columns exist before writing a query.

List All Tables

Before you can describe a table, you may need to know which tables exist in the current database:

SHOW TABLES;

This works in MySQL and SQLite. And postgreSQL uses \dt in its command-line client, while SQL Server relies on a query against sys. tables Not complicated — just consistent..

Query the Metadata Directly

For maximum portability, query the information_schema that most modern databases provide:

SELECT column_name, data_type
FROM information_schema.columns
WHERE table_name = 'employees';

Because this is a standard SELECT query, you can filter, sort, and join it just like any other data. It is the most reliable approach when you need scripts that work across different database engines And that's really what it comes down to..

Display Data from Multiple Tables

Real applications rarely store everything in one table. To display related data, you combine tables with a JOIN:

SELECT employees.first_name, employees.last_name, departments.name
FROM employees
INNER JOIN departments
    ON employees.department_id = departments.id;

This query displays each employee alongside the name of their department, pulling information from both tables based on a shared key. The INNER JOIN returns only rows that have a match in both tables. Other join types, such as LEFT JOIN, include rows from the left table even when no match exists.

Conclusion

Displaying table data and structure is the foundation of working with SQL. The SELECT statement lets you retrieve exactly the rows and columns you need, while WHERE, ORDER BY, and LIMIT give you precise control over the output. Here's the thing — when you need to understand the shape of your data, DESCRIBE, SHOW TABLES, and information_schema queries reveal the underlying structure. Finally, JOIN connects related tables so you can display meaningful, complete information Most people skip this — try not to. Turns out it matters..

Mastering these commands turns a raw database into a readable, queryable source of insight. Start with simple SELECT statements, layer in filtering and sorting, and gradually combine tables as your needs grow. With this toolkit, you can explore any database confidently and turn its contents into answers The details matter here. Turns out it matters..

Worth pausing on this one.

Beyond the Basics: Shaping the Output

Once you can retrieve rows, the next step is shaping them into something decision-ready Not complicated — just consistent..

Summarize with Aggregates

Aggregate functions collapse many rows into a single value, and GROUP BY decides how the rows are bucketed:

SELECT department_id, COUNT(*) AS headcount, AVG(salary) AS avg_salary
FROM employees
GROUP BY department_id
HAVING COUNT(*) > 5
ORDER BY avg_salary DESC;

Note the division of labor: WHERE filters rows before grouping, while HAVING filters the groups after aggregation. Swapping them is a common source of errors Not complicated — just consistent..

Compute Columns and Label Them

You can build expressions on the fly and give them readable names:

SELECT first_name || ' ' || last_name AS full_name,
       salary * 1.10 AS projected_salary
FROM employees;
New on the Blog

Just Released

Related Territory

Round It Out With These

Thank you for reading about How To Display Table In Sql. We hope the information has been useful. Feel free to contact us if you have any questions. See you next time — don't forget to bookmark!
⌂ Back to Home