SQL: Lucky Customers - List the first and last names of all customers whose first names start with the letters

Lucky Customers

Description: List the first and last names of all customers whose first names start with the letters 'A', 'J' or 'T' or last names end with the substring 'on'. Arrange them alphabetically in the order of their first names.

Sample Output

Select firstname, Lastname from Table_Name
where Firstname Like 'J%' OR Firstname Like 'A%' OR  Firstname Like 'T%' 
AND Lastname Like '%on'
order by Firstname;

NOTE: % here means 0 or more characters. Therefore, J% denotes a name that should start with J and can have 0 or more characters after that. Also, %on denotes a name that should end with 'on' and can have 0 or more characters before 'on'.

There is error in the code. Not working. 

Select first_name, Last_name from table_name
where First_name Like 'J%' OR First_name Like 'A%' OR  First_name Like 'T%' 
or Last_name Like '%on'
order by First_name;

 

The table name mentioned by above query is wrong. Please try this below query.

Select first_name, Last_name from customer
where First_name Like 'J%' OR First_name Like 'A%' OR  First_name Like 'T%' 
or Last_name Like '%on'
order by First_name;

Hope this query helps you.

Below Query is updated as per the question:

SELECT
   FIRST_NAME,
   LAST_NAME 
FROM
   customer
WHERE
   (FIRST_NAME LIKE 'J%'
   OR
   FIRST_NAME LIKE 'A%'
   OR
   FIRST_NAME LIKE 'T%')
   OR
   LAST_NAME LIKE '%on'
ORDER BY
   FIRST_NAME;