Hi I would like to select column from one table while ordering from column of another table. Effect should be same as this SQL:
SELECT DISTINCT m.marker_name FROM Marker m INNER JOIN Lease l ON m.marker_name = l.marker_name ORDER BY l.location
Table marker
╔═════════════╗
║ marker_name ║
╠═════════════╣
║ ABC ║
╟─────────────╢
║ DEF ║
╚═════════════╝
Table lease:
╔══════════╤═════════════╗
║ location │ marker_name ║
╠══════════╪═════════════╣
║ 01-01 │ ABC ║
╟──────────┼─────────────╢
║ 01-02 │ DEF ║
╟──────────┼─────────────╢
║ 01-01 │ GHI ║
╟──────────┼─────────────╢
║ 01-02 │ JKL ║
╚══════════╧═════════════╝
I tried with following JPA/Hibernate SQL but failed:
@Query("SELECT DISTINCT m.markerName FROM Marker m INNER JOIN Lease l ON m.marker_name = l.marker_name ORDER BY l.location")
List<String> findDistinctMarkernameOrderByLocation();
Error:
Path expected for join! [SELECT DISTINCT l.markerName FROM Lease l INNER JOIN Marker m ON m.marker_name = l.marker_name ORDER BY l.location]
I am trying to avoid use of native query so just wonder if any JPQL will work.