AdventureWorks Database: Retrieve persons last name begins with R

SQL Query - AdventureWorks: Exercise-31 with Solution

31. From the following table write a query in SQL to retrieve those persons whose last name begins with letter 'R'. Return lastname, and firstname and display the result in ascending order on firstname and descending order on lastname columns.

Sample table: Person.Person

Click to view Full table

Sample Solution:

SELECT LastName, FirstName 
FROM Person.Person  
WHERE LastName LIKE 'R%'  
ORDER BY FirstName ASC, LastName DESC ;

Sample Output:

lastname      |firstname  |
Russell       |Aaron      |
Ross          |Aaron      |
Roberts       |Aaron      |
Rana          |Abby       |
Raman         |Abby       |
Russell       |Abigail    |
Ross          |Abigail    |
Ross          |Abigail    |
Rogers        |Abigail    |
Rodriguez     |Abigail    |
Robinson      |Abigail    |
Rivera        |Abigail    |
Richardson    |Abigail    |
Reed          |Abigail    |
Ramirez       |Abigail    |
Russell       |Adam       |
Ross          |Adam       |

SQL AdventureWorks Editor:

Practice Online

Contribute your code and comments through Disqus.

Previous: Records of employees, order on hiredate.
Next: Order a table in ASC or DESC condionally.

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

How to create a foreign key in SQL Server?

create table question_bank
    question_id uniqueidentifier primary key,
    question_exam_id uniqueidentifier not null,
    question_text varchar(1024) not null,
    question_point_value decimal,
    constraint fk_questionbank_exams foreign key (question_exam_id) references exams (exam_id)

Database: SQL Server

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