Write a query to display the customer id, customer name, guardian name, reference account holders name of the customers who are referenced / referred by the relation 'NEIGHBOUR'(case-sensitive). Display the records sorted in ascending order based on customer id.
Question
Write a query to display the customer id, customer name, guardian name, reference account holders name of the customers who are referenced / referred by the relation 'NEIGHBOUR'(case-sensitive). Display the records sorted in ascending order based on customer id.
Solution
Assuming you are using SQL, the query would look something like this:
SELECT customer_id, customer_name, guardian_name, reference_account_holder_name
FROM customers
WHERE reference_relation = 'NEIGHBOUR'
ORDER BY customer_id ASC;
Here's a step-by-step breakdown of the query:
-
SELECT customer_id, customer_name, guardian_name, reference_account_holder_name: This part of the query specifies the columns that you want to display in your result. In this case, you want to display the customer id, customer name, guardian name, and the name of the reference account holder. -
FROM customers: This part of the query specifies the table from which you want to retrieve data. In this case, you are retrieving data from the 'customers' table. -
WHERE reference_relation = 'NEIGHBOUR': This is the condition for selecting rows in the table. Only rows where the 'reference_relation' column is 'NEIGHBOUR' will be selected. -
ORDER BY customer_id ASC: This part of the query sorts the result in ascending order based on the customer id. 'ASC' stands for 'ascending'. If you wanted to sort in descending order, you would use 'DESC' instead.
Similar Questions
Find the names of the customer that are not referred by the customer with id = 2.Return the result table in any order.The result format is in the following example.
Write a query to display the subject_name and subject_code of the subjects handled by the staff named 'Lakshmi'. Display the records sorted in ascending order based on subject_name.Note:1. Display only the subject_name and subject_code of the subjects handled by the staff named 'Lakshmi'.2. Use Joins. Tables involved are subject and staff3. Order by is mandatory.
Select all records from the Customers table, sort the result reversed alphabetically by the column City.
Write a query to display the person_name and contact_number from the 'travel_card'.Display the records in ascending order based on the person_name.Note:1. Display only the column named person_name and contact_number present in the travel_card table.2. Order by is mandatorySample output: [Only few records are shown here]
Use a UNION to create a list of all the employee's and customer's first names and last names ordered by the last name in descending order.
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.