I need query that will give me this result.
我需要查询才会给我这个结果。
Here are my 3 tables. Columns IDgolub
, IDmajka
and IDotac
from mg_popis_golubova
refers to ID from mg_golub
. Column IDstatus
from mg_popis_golubova
refers to ID from mg_status
.
这是我的3张桌子。来自mg_popis_golubova的列IDgolub,IDmajka和IDotac是指来自mg_golub的ID。来自mg_popis_golubova的列IDstatus是指来自mg_status的ID。
This is my query that I'm using to accomplish this. But it is not working. Because it merge nly column IDgolub
from mg_popis_golubova
and column ID
from mg_golub
. What about IDgolub
, IDmajka
. How to merge those two columns to ID
to get results.
这是我用来完成此任务的查询。但它没有用。因为它合并了来自mg_popis_golubova的列IDgolub和来自mg_golub的列ID。怎么样IDgolub,IDmajka。如何将这两列合并到ID以获得结果。
SELECT
mg_golub.ID AS IDgolub, mg_golub.brojgoluba, mg_golub.spol, mg_golub.boja, mg_golub.rasa, mg_golub.ime, mg_golub.godina, mg_status.status
FROM mg_golub
JOIN mg_status ON (mg_status.ID=mg_golub.IDstatus)
JOIN mg_popis_golubova ON (mg_golub.ID=mg_popis_golubova.IDgolub)
WHERE mg_popis_golubova.IDkorisnik='$ID_KORISNIK'
1 个解决方案
#1
2
I think this might be what you're looking for. You need to join the mg_golub
table multiple times to get the results you're looking for, which means you need to use table aliases.
我想这可能就是你要找的东西。您需要多次加入mg_golub表以获得您正在寻找的结果,这意味着您需要使用表别名。
SELECT
mg_golub.ID AS IDgolub, mg_golub.brojgoluba, mg_golub.spol, mg_golub.boja,
mg_golub.rasa, mg_golub.ime, mg_golub.godina, mg_status.status,
otac.brojgoluba, majka.brojgoluba
FROM mg_golub g
JOIN mg_status s ON (s.ID=g.IDstatus)
JOIN mg_popis_golubova pg ON (g.ID=pg.IDgolub)
JOIN mg_golub otac on (pg.IDotac = otac.ID)
JOIN mg_golub majka on (pg.IDmajka = majka.ID)
WHERE mg_popis_golubova.IDkorisnik='$ID_KORISNIK'
I'm not familiar with the language your table and column names are in, so I'm sure you can come up with much better aliases that I have.
我不熟悉你的表和列名所在的语言,所以我相信你可以提出我所拥有的更好的别名。
#1
2
I think this might be what you're looking for. You need to join the mg_golub
table multiple times to get the results you're looking for, which means you need to use table aliases.
我想这可能就是你要找的东西。您需要多次加入mg_golub表以获得您正在寻找的结果,这意味着您需要使用表别名。
SELECT
mg_golub.ID AS IDgolub, mg_golub.brojgoluba, mg_golub.spol, mg_golub.boja,
mg_golub.rasa, mg_golub.ime, mg_golub.godina, mg_status.status,
otac.brojgoluba, majka.brojgoluba
FROM mg_golub g
JOIN mg_status s ON (s.ID=g.IDstatus)
JOIN mg_popis_golubova pg ON (g.ID=pg.IDgolub)
JOIN mg_golub otac on (pg.IDotac = otac.ID)
JOIN mg_golub majka on (pg.IDmajka = majka.ID)
WHERE mg_popis_golubova.IDkorisnik='$ID_KORISNIK'
I'm not familiar with the language your table and column names are in, so I'm sure you can come up with much better aliases that I have.
我不熟悉你的表和列名所在的语言,所以我相信你可以提出我所拥有的更好的别名。