Hi,
I've got this BIG select statement that joins three tables:
mysql> select nameCode,nameTitle,if((relateItem = 1) OR (relateLink = 1),'YES','NO') LINK from iName LEFT JOIN iRelate ON (nameCode = relateLink OR nameCode = relateItem) LEFT JOIN iRelType ON relateType = typeID WHERE nameCode <> 1;
The value '1' will be a variable that represents the product that we are currently browsing. The value of LINK is dependent on whether the product listed is related to product '1' or not. iRelate supplies the definition of the relationship.
Here are the results below:
+----------+---------------------+------+
| nameCode | nameTitle | LINK |
+----------+---------------------+------+
| 00000014 | Magruder X5000 | NO |
| 00000003 | StreetXX | YES |
| 00000010 | KRacer | NO |
| 00000009 | Aero Racer I | YES |
| 00000007 | Digger | NO |
| 00000013 | RuggedXX | NO |
| 00000011 | doodle | NO |
| 00000011 | doodle | YES |
| 00000012 | floop | NO |
| 00000015 | Flanders C200 | NO |
| 00000016 | Ministry of Defence | NO |
| 00000016 | Ministry of Defence | NO |
| 00000016 | Ministry of Defence | YES |
| 00000017 | Leviathan | NO |
| 00000018 | Scoot Titanium | YES |
| 00000019 | SpiderFive | NO |
| 00000020 | Super 1 Spoke | YES |
+----------+---------------------+------+
17 rows in set (0.00 sec)
What is wrong here is that I only want the product to appear once - with YES if it's linked of NO if it's not. Because the iRelate table shows that product 'doodle' is also linked to another product - it gets mentioned again. DISTINCT does not work - because LINK is included in it's remit.
Can DISTINCT be used just to compile the initial list of products an then LINK is evaluated outside of this?
Do you see what I mean?
Ian
What I'm after is a list of ALL products - and then