忽略MS Access中的某一列 SELECT DISTINCTROW

问题描述 投票:-1回答:1

我有一个SQL查询。

SELECT DISTINCTROW Title, Author, Genre, ISBN, UID, YearPurchased, Condition
from " + table + "
WHERE " + condition + " " + defOrder + ";

通过Java中的UCanAccess调用。

有没有什么方法,使用SQL,将查询输出到一个ResultSet(我已经编好了,并且可以使用),在这个ResultSet中,后续记录中重复的Titles和ISBNs(当布尔值为真时)会被删除(其他列名也可能有重复)。

示例查询。

SELECT DISTINCTROW Title, Author, Genre, ISBN, UID, YearPurchased, Condition 
from tblBooks 
WHERE (Title LIKE 'spit*' OR Author LIKE 'spit*' OR Genre LIKE 'spit*') AND Loaned = No 
ORDER BY Title;

希望的输出是没有第2条记录。

https:/prnt.cs67k2q

java sql ms-access ucanaccess
1个回答
0
投票

你可以使用聚合。 我不知道你到底在定义什么单行,但这对你提供的数据是有效的。

SELECT Title, Author, Genre, ISBN, MIN(UID) as UID, YearPurchased, Condition
from " + table + "
WHERE " + condition + " " + defOrder + "
GROUP BY Title, Author, Genre, ISBN, YearPurchased, Condition
© www.soinside.com 2019 - 2024. All rights reserved.