Syntax:
SELECT column1, column2....
FROM table_name AS alias_name
WHERE [condition];
SELECT column_name AS alias_name
FROM table_name
WHERE [condition];
Consider the following Student table:
ID | Name | Marks |
1 | John | 64.12 |
2 | Sam | 72.50 |
3 | Alan | 45.90 |
4 | Rabecca | 86.37 |
5 | Anjali | 92.01 |
and Address_S table:
ID | Address |
---|---|
1 | DELHI |
2 | MUMBAI |
3 | CHENNAI |
4 | NOIDA |
5 | PANIPAT |
Query to fetch data from both tables using SQL Alias(Table Alias):
SELECT S.ID, S.NAME, S.MARKS, A.ADDRESS
FROM STudent AS S, ADDRESS_S AS A
WHERE S.ID = A.ID;
ID | Name | Marks | Address |
1 | John | 64.12 | DELHI |
2 | Sam | 72.50 | MUMBAI |
3 | Alan | 45.90 | CHENNAI |
4 | Rabecca | 86.37 | NOIDA |
5 | Anjali | 92.01 | PANIPAT |
Query for Column Alias:
SELECT ID AS STUDENT_ID, NAME AS STUDENT_NAME
FROM STUDENT
WHERE MARKS > 80;
STUDENT_ID | STUDENT_Name |
4 | Rabecca |
5 | Anjali |
Note: also read about SQL Functions-II
Please follow me to read my latest post on programming and technology if you like my post.
https://www.instagram.com/coderz.py/
https://www.facebook.com/coderz.py
Staying up to the mark is what defines me. Hi all! I’m Rabecca Fatima a keen learner, great enthusiast, ready to take new challenges as stepping stones towards flying colors.
You are given a stream of elements that is too large to fit into memory.…
The formula for the area of a circle is given by πr². Use the Monte…
Given an integer k and a string s, write a function to determine the length…
There is a staircase with N steps, and you can ascend either 1 step or…
Build an autocomplete system that, given a query string s and a set of possible…
Design a job scheduler that accepts a function f and an integer n. The scheduler…