Site icon IT Tutorial

Oracle SQL Tutorial -8 Comparative Operators

Hi ,

In this article I will tell you some operators .

Comparison operators When we want to compare data, for example, there are statements that make it easier for us to find the name we are looking for in more than one name.

BETWEEN OPERATOR

SELECT CUST_FIRST_NAME,CUST_LAST_NAME,CUST_YEAR_OF_BIRTH FROM SH.CUSTOMERS WHERE CUST_YEAR_OF_BIRTH BETWEEN 1950 AND 1964;

IN OPERATOR

SELECT CUST_FIRST_NAME,CUST_LAST_NAME_CUST_ID FROM SH.CUSTOMERS WHERE CUST_ID IN(3228,7673,4115);

LIKE OPERATOR

For example : If we want to list the people with the letter “e” in their name :

SELECT DISTINCT CUST_FIRST_NAME,CUST_LAST_NAME FROM SH.CUSTOMERS WHERE CUST_FIRST_NAME LIKE '%e%';

For example : If we want to see people with the second character ‘ r ‘ in their last name:

SELECT DISTINCT CUST_FIRST_NAME,CUST_LAST_NAME FROM SH.CUSTOMERS WHERE CUST_LAST_NAME LIKE '_r%';

IS NULL OPERATOR

I want to explain this operator with an example . In the query I run below , I wanted to see the non-null marital status of the people in the table and I used IS NOT NULL command .

SELECT DISTINCT CUST_FIRST_NAME,CUST_LAST_NAME,CUST_MARITAL_STATUS FROM SH.CUSTOMERS WHERE CUST_MARITAL STATUS IS NOT NULL;

LOJİK OPERATOR

AND OPERATOR

SELECT CUST_FIRST_NAME,CUST_LAST_NAME,CUST_CITY,CUST,CITY_ID FROM SH.CUSTOMERS WHERE CUST_LAST_NAME LIKE '_b%' AND CUST_CITY_ID>=52500;

OR OPERATOR

SELECT CUST_FIRST_NAME,CUST_LAST_NAME,CUST_CITY,CUST_CITY_ID FROM SH.CUSTOMERS WHERE CUST_FIRST_NAME='Deb' OR CUST_CITY='Wymondham';

NOT OPERATOR

SELECT DISTINCT CUST_FIRST_NAME,CUST_LAST_NAME FROM SH.CUSTOMERS WHERE CUST_FIRST_NAME NOT LIKE '%b%';

ORDER-BY OPERATOR

When we want to sort the records taken with the select statement , we use them . If not specified , it is sorted from small to large by default . Use of :

SELECT kolon_adi
FROM tablo_adi
ORDER BY kolon_adi ASC | DESC
SELECT DISTINCT CUST_FIRST_NAME,CUST_LAST_NAME,CUST_YEAR_OF_BIRTH FROM SH.CUSTOMERS ORDER BY CUST_YEAR_OF_BIRTH ASC;

A different example :

SELECT EMPLOYEE_ID,JOB_ID,AVG(SALARY),COUNT(*)KISISAYISI FROM ADMIN.NEW_TABLE GROUP BY EMPLOYEE_ID,JOB_ID ORDER BY EMPLOYEE_ID;

 

See you in my next post.

Exit mobile version