w3resource

AdventureWorks Database: Retrieve all rows and columns from a table

SQL Query - AdventureWorks: Exercise-1 with Solution

1. From the following table write a query in SQL to retrieve all rows and columns from the employee table in the Adventureworks database. Sort the result set in ascending order on jobtitle.

Sample table: humanresources.employee


Click to view Full table

Sample Solution:

SELECT *  
FROM humanresources.employee  
ORDER BY jobtitle;

Sample Output:

businessentityid|nationalidnumber|loginid                     |jobtitle                                |birthdate |maritalstatus|gender|hiredate  |salariedflag|vacationhours|sickleavehours|currentflag|rowguid                             |modifieddate           |organizationnod
----------------+----------------+----------------------------+----------------------------------------+----------+-------------+------+----------+------------+-------------+--------------+-----------+------------------------------------+-----------------------+---------------
             245|363910111       |adventure-works\barbara1    |Accountant                              |1976-01-04|M            |F     |2009-02-18|true        |           58|            49|true       |3ffba84e-8e97-4649-a5e1-859649d83aae|2014-06-30 00:00:00.000|/4/2/4/        
             248|480951955       |adventure-works\mike0       |Accountant                              |1979-07-01|S            |M     |2009-03-08|true        |           59|            49|true       |ac35337d-7c75-4dee-bb11-6564f257fe18|2014-06-30 00:00:00.000|/4/2/7/        
             241|30845           |adventure-works\david6      |Accounts Manager                        |1983-07-08|M            |M     |2009-01-30|true        |           57|            48|true       |2dc9d534-f5d1-4a14-8282-0a2a0eb6fd4d|2014-06-30 00:00:00.000|/4/2/          
             246|663843431       |adventure-works\dragan0     |Accounts Payable Specialist             |1977-02-14|M            |M     |2009-02-11|false       |           63|            51|true       |51c54d34-064b-44f7-a6b1-7702bd491980|2014-06-30 00:00:00.000|/4/2/5/        
             247|519756660       |adventure-works\janet0      |Accounts Payable Specialist             |1979-03-09|M            |F     |2009-03-01|false       |           64|            52|true       |0c641d77-8675-493f-9947-8c65136559cd|2014-06-30 00:00:00.000|/4/2/6/        
             243|60517918        |adventure-works\candy0      |Accounts Receivable Specialist          |1976-02-23|S            |F     |2009-01-06|false       |           61|            50|true       |9e9f713b-707c-4f7e-9504-de188052a045|2014-06-30 00:00:00.000|/4/2/2/        
             244|931190412       |adventure-works\bryan1      |Accounts Receivable Specialist          |1984-09-20|S            |M     |2009-01-24|false       |           62|            51|true       |cb3e71ec-a381-4716-87df-d3841ab9795a|2014-06-30 00:00:00.000|/4/2/3/        
             242|363923697       |adventure-works\deborah0    |Accounts Receivable Specialist          |1976-03-06|M            |F     |2008-12-18|false       |           60|            50|true       |09f75454-028c-46ca-bc08-0147bd0220d7|2014-06-30 00:00:00.000|/4/2/1/        
             272|525932996       |adventure-works\janaina0    |Application Specialist                  |1985-01-30|M            |F     |2008-12-23|true        |           71|            55|true       |241535c7-7a31-4a6a-9e0d-a83c30c2edda|2014-06-30 00:00:00.000|/5/7/          
             268|314747499       |adventure-works\ramesh0     |Application Specialist                  |1988-03-13|S            |M     |2009-02-03|true        |           73|            56|true       |be190269-4003-4d7f-809e-7b3fdc235da8|2014-06-30 00:00:00.000|/5/3/          
...

SQL AdventureWorks Editor:

Practice Online


Contribute your code and comments through Disqus.

Previous: AdventureWorks Exercises Home.
Next: Retrieve all rows, columns using table aliasing.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Share this Tutorial / Exercise on : Facebook and Twitter

SQL: Tips of the Day

T-SQL Cast versus Convert?

CONVERT is SQL Server specific, CAST is ANSI.

CONVERT is more flexible in that you can format dates etc. Other than that, they are pretty much the same. If you don't care about the extended features, use CAST.

Ref : https://bit.ly/3VKT5M8