Informatics Practices

Write a query against the ADDRESS table to select a list of names and phone numbers. The output should match these requirements :

  • The name column should contain both the first and last names with a blank space between them. Use the string concatenation.
  • The second column will contain the phone number.
  • Phone number should be in the format (999) 999-9999. Use the SUBSTR function and CONCAT.
  • Order the query by last name then first name.

Table ADDRESS ( contains following eight columns)

LastName    VARCHAR(25),
FirstName    VARCHAR(25),
Street        VARCHAR(50),
City        VARCHAR(25)
State        CHAR(2),
Zip            NUMBER,
Phone        VARCHAR(12),
Ext            VARCHAR(5)

SQL Queries

1 Like

Answer

SELECT CONCAT(FirstName, ' ', LastName) AS Name, 
CONCAT('(', SUBSTR(Phone, 1, 3), ') ', 
SUBSTR(Phone, 4, 3), '-', 
SUBSTR(Phone, 7, 4)) AS Phone_Number
FROM ADDRESS
ORDER BY LastName, FirstName;

Answered By

1 Like


Related Questions