MySQL query to get all fields of customer having Y in their firstname or lastname in ascending order of their city names

MySQL select query, we will perform below actions.

  • List all customers who is active
  • List all customers who is active and ‘Y’ in their firstname
  • List all customers who is active and ‘Y’ in their lastname
  • List all customers who having ‘Y’ in their lastname or lastname (either one)
  • List all customers who having ‘Y’ in their lastname and lastname (in both)

List all customers who is active

SELECT * FROM customers where activeStatus ='Y';
List all customers who is active

List all customers who is active and ‘Y’ in their firstname

SELECT * FROM customers where first_name LIKE '%Y%' AND activeStatus ='Y';
List all customers who is active and ‘Y’ in their firstname

List all customers who is active and ‘Y’ in their lastname

SELECT * FROM customers where last_name LIKE '%Y%' AND activeStatus ='Y';
List all customers who is active and ‘Y’ in their lastname

List all customers who having ‘Y’ in their lastname or lastname (either one)

 SELECT * FROM `customers` WHERE (first_name LIKE'%Y%' OR last_name LIKE '%Y%') ORDER BY city ASC;
List all customers who having ‘Y’ in their lastname or lastname (either one)

List all customers who having ‘Y’ in their lastname and lastname (in both)

SELECT * FROM `customers` WHERE first_name LIKE'%Y%' AND last_name LIKE '%Y%' ORDER BY city ASC;
List all customers who having ‘Y’ in their lastname and lastname (in both)

Pradip Mehta

I am a well-organized professional in Drupal Development and PHP web development with strong script handling knowledge or automation process with PHP. I have advanced computer skills and am a proficient multitasker.