![]() In this scenario, a UNION is used to combine data from different tables. In this scenario, you don’t want a Cartesian product. You may want to integrate all of the supplier information maintained in several tables, as in the previous example. There are additional reasons to join two tables that don’t have a common column. This syntax is more readable for the users and it also clearly states the purpose of CROSS JOIN. This query produces the same result as earlier. Mostly, CROSS JOIN is used for this type of operation. This is one of the approaches for joining two tables together when the objective is to get a result set with all possible combinations of the rows but this is not the best approach. This query provides a cross join, or cartesian product, with a total number of rows equal to the first table’s number of rows multiplied by the second table’s number of rows. SELECT w.name AS wine, m.name AS main_course There is no need to specify any joining conditions if all we want is every combination of rows from two tables. ![]() Two tables are joined with the help of FROM clause and then use the WHERE clause if necessary. We simply join the two tables together with this syntax. In our first example, we want all the possible combinations of wines and main course for our menu.įirst, we will use the FROM TABLE 1, TABLE 2 Syntax: The main course table contains the main course id, the main course name, the major supplier ID for this meal, and the price: id The wine table contains the wine ID, the name of the wine, the supplier ID, and the price: id Suppose there is a restaurant and they have two tables wine and main_courser in their database. ![]() In this post, I’ll explain different solutions with examples. This is not a join but can be useful for merging tables in SQL. There are few ways to combine the two tables without a common column including Cross Join (Cartesian Product) and UNION.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |