简体   繁体   中英

MS Access 2010 - SQL Query using RIGHT JOIN - Returning too much values

I'm trying to make this query but it's returning too much rows

SELECT 
Denuncia.codigoAsociado,    
Involucrado.nombreCompleto 
FROM 
Denuncia 
RIGHT JOIN 
Involucrado ON Denuncia.ID = Involucrado.idDenuncia

I would like to get one codigoAsociado and one nombreCompleto. I have tried using DISTINCT but it's the same.

This is the result (check the link) Sorry can't post images

http://oi62.tinypic.com/2l9gwnp.jpg

I need it to look like this

codigoAsociado | nombreCompleto

341130402 | Juan Carlos Espinoza López

341131290 | Carlos Queirolo Rochabrun

.

.

.

341131600 | Enrique Froemel

341131949 | Raúl Muñoz

Thanks in advance

I use Oracle DB but in Access should work this:

SELECT 
TOP 1 Denuncia.codigoAsociado,    
Involucrado.nombreCompleto 
FROM 
Denuncia 
RIGHT JOIN 
Involucrado ON Denuncia.ID = Involucrado.idDenuncia

The TOP number tell you how many rows will be returned. You should also use TOP 10 PERCENT and it returns first 10% of records.

If you need only unique records, try to use this code

SELECT 
DISTINCT Denuncia.codigoAsociado,    
Involucrado.nombreCompleto 
FROM 
Denuncia 
RIGHT JOIN 
Involucrado ON Denuncia.ID = Involucrado.idDenuncia

DISTINCT in Access has been also discussed in this post how to use distinct in ms access .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM