0

如何加入这 4 个不同的表,以便我可以获得字符串结果而不是数字。这是我到目前为止的查询

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_drzava.drzava, mg_status.status
FROM mg_golub
JOIN mg_drzava 
  ON (mg_drzava.ID=mg_golub.IDdrzava)
JOIN mg_status 
  ON (mg_status.ID=mg_golub.IDstatus)
LEFT JOIN mg_popis_golubova AS Otac 
  ON (Otac.IDotac=mg_golub.ID)
LEFT JOIN mg_popis_golubova AS Majka 
  ON (Majka.IDmajka=mg_golub.ID)
JOIN mg_popis_golubova 
  ON (mg_golub.ID=mg_popis_golubova.IDgolub) 
WHERE mg_popis_golubova.IDkorisnik='$ID_KORISNIK' 

我不知道如何将这 3 个字段从 mg_popis_golbova 链接到 mg_golub。我被困住了,因为我无法为这两列选择数据。

LEFT JOIN mg_popis_golubova AS Otac ON (Otac.IDotac=mg_golub.ID)
LEFT JOIN mg_popis_golubova AS Majka ON (Majka.IDmajka=mg_golub.ID)

在此处输入图像描述

INSERT INTO `mg_golub` (`ID`, `IDkorisnik`, `brojgoluba`, `spol`, `boja`, `rasa`, `ime`, `godina`, `IDdrzava`, `IDstatus`) VALUES
(1, 1, '06557-07-681', 'X', 'kovana', 'Koopman x Schellens', 'Dirk', 2000, 2, 3),
(2, 1, '07216-05-552', 'X', 'kovana', 'Koopman', 'Tata', 2001, 2, 3),
(3, 1, '2081-01-271', 'Y', 'kovana', 'Schellens', 'Die Weischwantaubi', 2003, 2, 3);

INSERT INTO `mg_popis_golubova` (`ID`, `IDkorisnik`, `IDgolub`, `IDmajka`, `IDotac`) VALUES
(28, 1, 1, 3, 2),
(27, 1, 3, 0, 0),
(26, 1, 2, 0, 0);
4

1 回答 1

0

尝试这个

   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_drzava.drzava, mg_status.status
FROM mg_golub
JOIN mg_drzava 
  ON (mg_drzava.ID=mg_golub.IDdrzava)
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' 
于 2013-05-23T16:04:00.443 回答