Diğer tablolara 3 yabancı anahtar kullanan bir tablom var. Sol bir katılım gerçekleştirdiğimde, yinelenen sütunları alıyorum. MySQL, USING
sözdiziminin yinelenen sütunları azaltacağını, ancak birden çok tuşa örnek olmadığını söylüyor.MySQL: Sol Katmanda çift sütunları kaldırma, 3 tablo
Verilen:
mysql> describe recipes;
+------------------+------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------------+------------------+------+-----+---------+-------+
| ID_Recipe | int(11) | NO | PRI | NULL | |
| Recipe_Title | char(64) | NO | | NULL | |
| Difficulty | int(10) unsigned | NO | | NULL | |
| Elegance | int(10) unsigned | NO | | NULL | |
| Quality | int(10) unsigned | NO | | NULL | |
| Kitchen_Hours | int(10) unsigned | NO | | NULL | |
| Kitchen_Minutes | int(10) unsigned | NO | | NULL | |
| Total_Hours | int(10) unsigned | NO | | NULL | |
| Total_Minutes | int(10) unsigned | NO | | NULL | |
| Serving_Quantity | int(10) unsigned | NO | | NULL | |
| Description | varchar(128) | NO | | NULL | |
| ID_Prep_Text | int(11) | YES | | NULL | |
| ID_Picture | int(11) | YES | | NULL | |
| Category | int(10) unsigned | NO | | NULL | |
| ID_Reference | int(11) | YES | | NULL | |
+------------------+------------------+------+-----+---------+-------+
15 rows in set (0.06 sec)
mysql> describe recipe_prep_texts;
+------------------+---------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------------+---------------+------+-----+---------+-------+
| ID_Prep_Text | int(11) | NO | PRI | NULL | |
| Preparation_Text | varchar(2048) | NO | | NULL | |
+------------------+---------------+------+-----+---------+-------+
2 rows in set (0.02 sec)
mysql> describe recipe_prep_texts;
+------------------+---------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------------+---------------+------+-----+---------+-------+
| ID_Prep_Text | int(11) | NO | PRI | NULL | |
| Preparation_Text | varchar(2048) | NO | | NULL | |
+------------------+---------------+------+-----+---------+-------+
2 rows in set (0.02 sec)
mysql> describe mp_references;
+--------------+---------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------------+---------+------+-----+---------+-------+
| ID_Reference | int(11) | NO | PRI | NULL | |
| ID_Title | int(11) | YES | | NULL | |
| ID_Category | int(11) | YES | | NULL | |
+--------------+---------+------+-----+---------+-------+
3 rows in set (0.00 sec)
Benim sorgu ifadesi:
SELECT *
FROM Recipes
LEFT JOIN (Recipe_Prep_Texts, Recipe_Pictures, mp_References)
ON (
Recipe_Prep_Texts.ID_Prep_Text = Recipes.ID_Prep_Text AND
Recipe_Pictures.ID_Picture = Recipes.ID_Picture AND
mp_References.ID_Reference = Recipes.ID_Reference
);
Benim amacım yinelenen sütun olmadan katılmak tüm sütunların bir satır elde etmektir. SQL deyimlerini göndermek ve sonuç kümelerini almak için MySQL C++ Bağlayıcısı kullanıyorum. C++ Bağlayıcısı, yinelenen sütun adlarıyla ilgili sorunlara sahip olduğuna inanıyorum.
Kullanmam gereken SQL deyim sözdizimi nedir?
Reference to MySQL JOIN syntax
Bu, tablonun mevcut olmadığı durumlar dışında çalışır. Ben de bunun için kontroller yaptım. Ayrıca, bu, tabloların yabancı anahtar alanları dışında benzersiz sütun adlarına sahip olduğunu varsayar. Neyse ki, sahip olduğum şey bu. **Çok teşekkürler!** –