Still returns duplicate rows
Main Topics
Browse All TopicsHi,
I've got the need to select everything from table1 and only 1 row from table2. Table2 can hold any number of rows from 0 to 10,000
I've tried the following with no joy. Any ideas?
SELECT DISTINCT (ID) AS Expr1, *
FROM aacc LEFT JOIN awardsQuery ON aacc.ID = tbl2.feildID;
This still brings back IDs that are the same!
Regards
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
try this:
strSQL="SELECT DISTINCT ID FROM aacc LEFT JOIN awardsQuery ON aacc.ID = tbl2.feildID;"
set db=CurrentFB
set rst=db.Execute(strSQL)
if not (rst.eof and rst.bof) then
Do while not rst.eof
strSQL="SELECT * FROM aacc LEFT JOIN awardsQuery ON aacc.ID = tbl2.feildID AND ID = " & rst("ID") & ";"
set rst2=db.execute(strSQL)
if not (rst2.eof and rst2.bof) then
...............
'YOUR CODE HERE
end if
rst.MoveNext
Loop
end if
sorry
strSQL="SELECT DISTINCT ID FROM aacc LEFT JOIN awardsQuery ON aacc.ID = tbl2.feildID;"
set db=CurrentFB
set rst=db.Execute(strSQL)
if not (rst.eof and rst.bof) then
Do while not rst.eof
strSQL="SELECT * FROM aacc LEFT JOIN awardsQuery ON aacc.ID = tbl2.feildID AND ID = " & rst("ID") & ";"
set rst2=db.execute(strSQL)
if not (rst2.eof and rst2.bof) then
Do while not rst2.eof
'YOUR CODE HERE
..........................
rst2.Movenext
Loop
end if
rst.MoveNext
Loop
end if
There is a way to do this without any code scripting using a simple GROUP BY clause but you need to have a combination of columns in awardsQuery that are unique.
Below, I assume that you have an ID field in awardsQuery that is unique but you can do the same with a multi-columns unique key.
SELECT aacc.*, awardsQuery.*
FROM aacc
LEFT JOIN (SELECT fieldID, Min(ID) As MinID
FROM awardsQuery
GROUP BY fieldID) LowestID ON LowestID.fieldID = aacc.ID
LEFT JOIN awardsQuery on LowestID.ID = awardsQuery.ID
Please note that if aacc.ID is NOT unique you should add the DISTINCT keyword after the first SELECT
Hope this helps.
Business Accounts
Answer for Membership
by: 1makPosted on 2003-11-20 at 05:05:30ID: 9787010
The DISTINCT keyword acts on all of the fields returned, not just the first one (i.e. ID in your example).
If you were to explicitly name only the fields you wanted then i'm sure you'd get a better result.
e.g.
SELECT DISTINCT aacc.ID,
awardsQuery.Field1
FROM aacc
LEFT JOIN awardsQuery ON aacc.ID = awardsQuery.FieldID