J'ai lu quelques messages ici. En utilisant ce post (Select value A from the same record as max(value B) and then join with another table on value C) j'ai commencé ma requête mais cela ne fonctionne pas. Les requêtes SELECT imbriquées sont-elles autorisées dans Access?Joindre 2 tables sur la colonne x basé sur la valeur maximale de la colonne y dans la deuxième table
col
_______________________
|hole_id|max_depth|...|
| 1 | 340 | |
| 2 | 400 | |
| 3 | 250 | |
test
______________________
|hole_id|depth_to|...|
| 1 | 58 | |
| 1 | 62 | |
| 1 | 69 | |
| 2 | 102 | |
| 2 | 110 | |
| 3 | 20 | |
| 3 | 25 | |
Je dois retourner
________________________________
|hole_id|max_depth|depth_to|...|
| 1 | 340 | 69 | |
| 2 | 400 | 110 | |
| 3 | 250 | 25 | |
-
SELECT DISTINCT A.hole_id, A.max_depth, B.depth_from, B.depth_to
FROM collar A
LEFT JOIN assay B
ON A.hole_id = B.hole_id
WHERE A.hole_id = (
SELECT max(C.depth_to)
FROM assay C
WHERE C.hole_id = A.hole_id
)
WHERE A.max_depth > B.depth_to AND A.section="BLK" AND A.holetype="Exploration"
;
Je devrais mentionner que j'ai toutes sortes d'autres domaines, mais je ne pense pas qu'ils soient pertinents à la logique. – Elizabeth