mysql: Bir pivot tablo işleyicisi isteği?

0 Cevap php

Ben bir mysql sorum var:

mysql ile php kullanarak ben aslında şöyle bir şema var:

3 tablolar:

module
module_has_theme (pivot table)
theme

The idea behind this is to display the modules of my application using themes if they have, and if they don't, then display them in an extra category (other).

So let's say if I populate my module table with some modules : mod1, mod2, mod3, mod4, mod5

Then I create some themes : fruit, animals, number, human

Daha özet tablo I hayvanlarla mod1 bağlanır.

Sonra böyle istek (veya benzer bir şey) sonucunu istiyorum

sonuç:

fruit => null,
animals => mod1,
number => null,
human => null,
other => mod2, mod3, mod4, mod5

Actually, my code use 2 mysql requests and a php loop to do it,
(
first request takes all modules
second request takes all modules that have themes (using two inner join)
a php loop that organize modules the way I want using the two above resulting arrays
)

Now I was wondering if there would be a magic mysql request that would do the same job in 1 single request ?
Please if you know that let me know ;)

0 Cevap