-1

As written on the title, does CROSS JOIN not work for different tables with the same column name?

For example, I have one table named Fruits:

|  name  |  price  |
|  apple |    1    |
| banana |    2    |

and another table named Snacks:

|  name   |  price  |
|  chips  |    3    |
| cookies |    4    |

Then does

SELECT Fruits.price, Snacks.price FROM Fruits CROSS JOIN Snacks

does not work properly? I am working on a same issue, but the result shows like:

|  price  |  price  |
|    3    |    3    |
|    4    |    4    |
|    3    |    3    |
|    4    |    4    |

But what I expect is:

|  price  |  price  |
|    1    |    3    |
|    1    |    4    |
|    2    |    3    |
|    2    |    4    |
forpas
  • 160,666
  • 10
  • 38
  • 76
  • Not Possible. Probably your fruits table has 3,4 values. Show your exact data from both tables and select result. – Utsav Oct 02 '21 at 13:18

2 Answers2

1

As I mentioned in the comment, it is not possible. Either your tables values are different or your query.

Check this dbfiddle showing the result value same as your expected values.

Utsav
  • 7,914
  • 2
  • 17
  • 38
0

In MySQL CROSS JOIN works as expected:

 price  price 
 ------ ----- 
 1      3     
 2      3     
 1      4     
 2      4     

See running example at DB Fiddle.

The Impaler
  • 45,731
  • 9
  • 39
  • 76