CROSS JOIN tutorial in php
CROSS JOIN Syntax :
SELECT columns FROM table1 CROSS JOIN table2;
If we want to perform CROSS JOIN on two tables named "personaltwo" and "city" then we can use below shown sql query :
SELECT * FROM personaltwo CROSS JOIN city;
If we want to use alias name for table name "personaltwo" and "city" with CROSS JOIN then we can use below shown sql query :
In "personaltwo" table, column "city" is FOREIGN KEY and In "city" table, column "cid" is PRIMARY KEY.
SELECT * FROM personaltwo p CROSS JOIN city c;
If we want to select some specific columns from tables "personaltwo" and "city" with CROSS JOIN then we can use below shown sql query :
SELECT p.id, p.name, c.cityname FROM personaltwo p CROSS JOIN city c;
If we want to change the column name from "name" to "Name" and "cityname" to "CityName" with CROSS JOIN then we can use below shown sql query :
SELECT p.id, p.name AS Name, c.cityname AS CityName FROM personaltwo p CROSS JOIN city c;
We can perform above same operation using below shown sql query :
Both the query will work same.
SELECT p.id, p.name AS Name, c.cityname AS CityName FROM personaltwo p, city c;
Comments
Post a Comment