SQL topics

Database Basics

Retrieving Columns of Data from a Database Table

Sorting Columns Retrieved from a Database Table

Filtering Data Retrieved from a Database Table

Updating Data in SQL

Also see

Weekly Feedback Blog

SQL Survey Results

ColdFusion

Website Development


SfC Home > Web Design > SQL >

Explanation of Retrieving Columns of Data from a Database Table - Succeed in Using SQL. Also refer to Structured Query Language, Access, MySQL, MS SQL Server, SELECT, wildcard, comma, Ron Kurtus, School for Champions. Copyright © Restrictions

Retrieving Columns of Data from a Database Table in SQL

by Ron Kurtus (3 February 2007)

You can use SQL to retrieve the columns of a database table with the SELECT statement. You can retrieve all columns, a single column, or several specific columns. It is then up to your programming language to display that data.

Questions you may have include:

This lesson will answer those questions. There is a mini-quiz near the end of the lesson.

Retrieve all columns

You can query a database to retrieve all the elements in a database table by using the SELECT statement and wildcard (*) indicator.

SELECT *
FROM table_name;

Note: It is standard practice to add ";" at the end of your SQL query. Some databases require it and some don't.

Retrieve single column

The most common query from a database is to collect or retrieve all the elements in a specific column of the database table.

SELECT column_name
FROM table_name;

Retrieve several select columns

You can also retrieve data from several columns by separating the column names with a comma.

SELECT column_1, column_2, column_7
FROM table_name;

Note: Do not place a comma after the last item in the list, because it will result in an error message.

Summary

The SELECT statement is used to retrieve the columns of a database table. You can retrieve all columns, a single column, or several specific columns.

Answers to Readers' Questions


Always do your best


Resources

The following are resources on this subject.

Websites

SQL Resources

Books

Top-rated books on SQL


Mini-quiz to check your understanding

1. What is a "wildcard" symbol mean?

It means you should show nothing

It means that all items are included

It has no real meaning and is used to fill in space

2. Why is ";" used after the table name?

It is a convention used to indicate the end of your query statement

All table names must include ";"

That was a typo

3. Does the order you list the columns matter?

Yes, because otherwise SQL cannot find them

It depends what programming language you are using

No, although usually you list them as they are in the table

If you got all three correct, you are on your way to becoming a Champion in working with SQL. If you had problems, you had better look over the material again.


What do you think?

Do you have any questions, comments, or opinions on this subject? If so, send an email with your feedback. We will try to get back to you as soon as possible.


Share link

Feel free to establish a link from your website to pages in this site.

Or use our form to send this link to yourself or a friend.


Students and researchers:

The Web address of this page is:
www.school-for-champions.com/sql/retrieving_columns.htm.

Please include it as a reference in your report, document, or thesis.


Where are you now?

School for Champions

SQL topics

Retrieving Columnsof Data from a Database Table in SQL



Live Your Life as a Champion:

Take care of your health

Seek knowledge and gain skills

Do excellent work

Be valuable to others

Have utmost character

Be a Champion!



The School for Champions helps you become the type of person who can be called a Champion.