Informatics Practices
How is a cross join different from natural join ? Give example.
SQL Joins & Grouping
1 Like
Answer
A cross join is a very basic type of join that simply pairs every row from one table with every row from another table. On the other hand, a natural join is a join where only one of the identical columns from the joined tables exists.
1. CROSS JOIN Example:
SELECT *
FROM students
CROSS JOIN subjects;
This CROSS JOIN will pair every row from the students table with every row from the subjects table, resulting in a Cartesian product of the two tables.
2. NATURAL JOIN Example:
SELECT *
FROM students
NATURAL JOIN subjects;
This NATURAL JOIN will automatically match the common columns and return rows where the values match.
Answered By
2 Likes
Related Questions
In a database BANK, there are two tables with a sample data given below:
Table: EMPLOYEE
ENo EName Salary Zone Age Grade Dept 1 Mona 70000 East 40 A 10 2 Mukhtar 71000 West 45 B 20 3 Nalini 60000 East 26 A 10 4 Sanaj 65000 South 36 A 20 5 Surya 58000 North 30 B 30 Table: DEPARTMENT
Dept DName HOD 10 Computers 1 20 Economics 2 30 English 5 (a) To display ENo, EName, Salary and corresponding DName of all the employees whose age is between 25 and 35 (both values inclusive).
(b) To display DName and corresponding EName from the tables DEPARTMENT and EMPLOYEE (Hint: HOD of DEPARTMENT table should be matched with ENo of EMPLOYEE table for getting the desired result).
(c) To display EName, Salary, Zone and Income Tax (Note: Income tax to be calculated as 30% of salary) of all the employees with appropriate column headings.
How is a left join different from a natural join ? Give example.
A table "TRAINS" in a database has degree 3 and cardinality 8. What is the number of rows and columns in it ?
In a database there are two tables "Product" and "Client" as shown below :
Table : Product
P_ID ProductName Manufacture Price P001 Moisturiser XYZ 40 P002 Sanitizer LAC 35 P003 Bath Soap COP 25 P004 Shampoo TAP 95 P005 Lens Solution COP 350 Table : Client
C_ID ClientName City P_ID 01 Dreamz Disney New Delhi P002 05 Life Line Inc Mumbai P005 12 98.4 New Delhi P001 15 Appolo Banglore P003 Write the commands in SQL queries for the following :
(i) To display the details of Product whose Price is in the range of 40 and 120 (Both values included).
(ii) To display the ClientName, City from table Client and ProductName and Price from table Product, with their corresponding matching P_ID.
(iii) To increase the Price of all the Products by 20.