Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL SELECT between two non-joinable tables

I have a two tables

Users
- ID

Preferences
- ID
- Name
- Value

There are no values between the two tables that can be joined on.

If I have two users and two preferences is there a way to get the following in a single SQL SELECT statement to get the following result:

User1.ID, Preference1.Name, Preference1.Value
User1.ID, Preference2.Name, Preference2.Value
User2.ID, Preference1.Name, Preference1.Value
User2.ID, Preference2.Name, Preference2.Value

Basically I would like to make a UserPreferences SQL View where every user is assigned every preference.

like image 725
Alex Meyer Avatar asked May 11 '26 16:05

Alex Meyer


1 Answers

Use a cross join to create a cartesian product:

select u.id, p.name, p.value
from users u cross join preferences p 
like image 196
sgeddes Avatar answered May 14 '26 05:05

sgeddes