w3resource

SQL Exercises: Display all information about all salespeople

SQL Basic Select Statement: Exercise-1 with Solution

Write a SQL statement that displays all the information about all salespeople.

Sample table: salesman

 salesman_id |    name    |   city   | commission 
-------------+------------+----------+------------
        5001 | James Hoog | New York |       0.15
        5002 | Nail Knite | Paris    |       0.13
        5005 | Pit Alex   | London   |       0.11
        5006 | Mc Lyon    | Paris    |       0.14
        5007 | Paul Adam  | Rome     |       0.13
        5003 | Lauson Hen | San Jose |       0.12

Sample Solution:

SQL Code:

-- This query selects all columns from the 'salesman' table.
SELECT * 
-- Specifies the table from which to retrieve the data (in this case, 'salesman').
FROM salesman;

Output of the Query:

salesman_id	name		city		commission
5001		James Hoog	New York	0.15
5002		Nail Knite	Paris		0.13
5005		Pit Alex	London		0.11
5006		Mc Lyon		Paris		0.14
5007		Paul Adam	Rome		0.13
5003		Lauson Hen	San Jose	0.12

Code Explanation:

The said query in SQL that selects all columns from the table 'salesman'. It returns all the rows and columns of the table salesman.

SQL syntax:

SELECT [DISTINCT] [<qualifier>.]<column_name> |*|
<expression>
[AS <column_alias>],...
FROM <table_or_view_name> |
<inline_view>
[[AS] <table_alias>]
[WHERE <predicate>]
[GROUP BY [<qualifier>.]<column_name>,...
[HAVING <predicate>]
]
[ORDER_BY <column_name> |
<column_number>
[ASC | DESC],...
];

Note: Use * to get a complete list of the columns from a table.
Alternate command:
SELECT salesman_id, name, city, commission

SQL Exercises: Syntax of select all the columns from a table

Visual presentation:

Result of select all the columns from a table

Practice Online


Query Visualization:

Duration:

Query visualization of Select all the columns from a table - Duration

Rows:

Query visualization of Select all the columns from a table - Rows

Cost:

Query visualization of Select all the columns from a table - Cost

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous SQL Exercise: SQL Retrieve data from tables Exercises Home
Next SQL Exercise: Display a given string.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://www.w3resource.com/sql-exercises/sql-retrieve-exercise-1.php