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.
Given an integer A. Compute and return the square root of A. If A is…
Given a zero-based permutation nums (0-indexed), build an array ans of the same length where…
A heap is a specialized tree-based data structure that satisfies the heap property. It is…
What is the Lowest Common Ancestor? In a tree, the lowest common ancestor (LCA) of…
A Binary Search Tree (BST) is a type of binary tree that satisfies the following…