I’m creating a MySQL view for a server application that connects directly to the database server. I didn’t like the way the application’s schema is so I went with my own structure. Originally, I was going to use the data to create static configuration files, but that is no longer an option.
Anyway, I’ll be using several rows from different tables to create this view. There is a 1:many relationship between table A and the view and a 1:1 relationship for table B. It’s the 1:many that’s throwing me off.
In table A, I have the following:
+--------------------------------+ | id | name | timeout | any | +--------------------------------+ | 1 | Main | 10 | 1 | +--------------------------------+
In table B, I have the following:
+-------------------+ | id | a_id | route | +-------------------+ | 1 | 1 | 123 | +-------------------+ | 2 | 1 | 321 | +-------------------+
For the view, the two tables will be joined like so:
+-------------------------------------+ | name | app | data | +-------------------------------------+ | Main | timeout | 10 | +-------------------------------------+ | Main | dialany | 1 | +-------------------------------------+ | Main | routeto | 321 | +-------------------------------------+ | Main | routeto | 123 | +-------------------------------------+
I’m not even sure if there’s a name for this (or if it’s even possible) but any help to get started would be fantastic.
You’d use a
UNIONto get the individual rows from the first table, something like this:And then
UNIONin the other table:And you should have what you want.