Sunday, December 21, 2025

Your First SQL statement :)

 Using Oracle Free SQL  , 

  • Select HR schema to connect to all HR tables 
  • Write simple query like this 👇
    SELECT *
    FROM HR.EMPLOYEES
  • Press RUN button 
  • you will get the result like this 👇
        

  • you can select certain data like this 👇

    SELECT EMPLOYEE_ID , FIRST_NAME , LAST_NAME
    FROM HR.EMPLOYEES   

  • you will get the result like this 👇

 

Explanation of code:

as you see EMPLOYEES table has many columns (data) , like
EMPLOYEE_ID, FIRST_NAME, LAST_NAME, EMAIL, PHONE_NUMBER, HIRE_DATE,
JOB_ID, SALARY, MANAGER_ID, DEPARTMENT_ID

you can select data by SELECT statement , the used SQL is simple one to get data from database

you can select data from one table , or many tables as will know later
you can get data as it is or format the result as well
you can filter data as needed as will know later

now , assume we need to get employees' full name ,
we can write SQL as this 👇 using symbol || which is the symbol to concatenate 2 string(character)

SELECT EMPLOYEE_ID , FIRST_NAME ||' '|| LAST_NAME   FULL_NAME
FROM HR.EMPLOYEES


as you see , we can set alias for the selected data , here FULL_NAME is called alias ,
which means a readable title for selected data

let's we need an alias with space like Hire Date , in this case we can use it inside "" and use AS clause as will see soon

now , we need to get full name , hire date in format of "dd Month yyyy" or any valid format , do you know how to get that ?

if you don't know ways to convert date to needed format , you can look at this help page

if you know how to format date , it is easy to write the SQL which will be

SELECT EMPLOYEE_ID , FIRST_NAME ||' '|| LAST_NAME   FULL_NAME
, TO_CHAR(HIRE_DATE,'DD Month YYYY')  as "Hire Date"
FROM HR.EMPLOYEES

here we use alias in 2 ways , just new title like FULL_NAME which is common used in programming ,
and new title with space like Hire Date , using as "Hire Date" , which is used for extract data to external files

the result will be like this 👇



this is how to write simple SQL statement, and in next post we will filter data using WHERE clause




No comments:

Post a Comment

Tree Query , Hierarchical Query in SQL

   In this lesson , We need to get the data from table has self foreign key  Using  Oracle Free SQL   , by s elect HR schema to connect to a...