I am just a new beginner in MySQL and I wanted to write the a SELECT statement that returns customers IDs and customer names(alphabetical order) for customers who live in Indiana, Ohio,Michigan, and Illinois, and whose names begin with the letters A or B.
Here is the CUSTOMER_TBL structure using the DESCRIBE CUSTOMER_TBL;
Name Null? Type
-------------------------------------------------------------
CUST_ID NOT NULL VARCHAR2(10)
CUST_NAME NOT NULL VARCHAR2(30)
CUST_ADDRESS NOT NULL VARCHAR2(20)
CUST_CITY NOT NULL VARCHAR2(12)
CUST_STATE NOT NULL CHAR(2)
CUST_ZIP NOT NULL CHAR2(5)
CUST_PHONE NUMBER(10)
CUST_FAX NUMBER(10)
Here is my solution.I just need to know if I am correct. thanks
SELECT CUST_ID,CUST_NAME FROM CUSTOMER_TBL
WHERE IN('Indiana','Ohio','Ohio','Michigan','Illinois') AND WHERE LIKE(A% OR B%)
ORDER BY CUST_ID,CUST_NAME
Your
CUST_STATEis aCHAR(2)column so I assume that it contains state codes, not state names. So instead of Indiana, Ohio etc you should use state codes:Correct the state codes in case they are wrong.