I have this code in SQL,and I just want extract the 3 big's values from my database(ACcess) working in DAO....but the code extract all the values >='90' and not the only 3 big values >='90'
something wrong with code?
VB Code:
sql1 = _
"select top 3 pontosind1 as Totais, classifind1 as Classifind, seccao1 as Secção, classe1 as Classe, designacao1 as Designação, nomesocio as Expositor, anilha1 as Anilha, gaiolaind1 as Gaiola, Sexo1 as Sexo" & _
The Select Top 3 is applied to the first query only. If you want to get the Top 3 from all queries in the union you will need to use a subquery. I am not sure if MSAccess supports subqueries.
Code:
sql1 = "Select Top 3 * From ( "_
"select pontosind1 as Totais, classifind1 as Classifind, seccao1 as Secção, classe1 as Classe, designacao1 as Designação, nomesocio as Expositor, anilha1 as Anilha, gaiolaind1 as Gaiola, Sexo1 as Sexo" & _
" from exposicao " & _
" WHERE pontosind1 >= '90' & _
"and (pontoseq1 = '' or pontoseq1 is null) " & _
" UNION ALL" & _
" select pontosind2, classifind2, seccao2, classe2, designacao2, nomesocio, anilha2, gaiolaind2, sexo2" & _
" from exposicao " & _
" WHERE pontosind2 >= '90' & _
"and (pontoseq1 = '' or pontoseq1 is null) " & _
" UNION ALL" & _
" select pontosind3, classifind3, seccao3, classe3, designacao3, nomesocio, anilha3, gaiolaind3, sexo3" & _
" from exposicao " & _
" WHERE pontosind3 >= '90' & _
"and (pontoseq1 = '' or pontoseq1 is null) " & _
" UNION ALL" & _
" select pontosind4, classifind4, seccao4, classe4, designacao4, nomesocio, anilha4, gaiolaind4, sexo4" & _
" from exposicao " & _
" WHERE pontosind4 >= '90' & _
"and (pontoseq1 = '' or pontoseq1 is null)) " & _
" ORDER BY classe desc,Totais desc "
I also do not use ACCESS, but if you have a problem with the SUBQUERY, maybe make a VIEW of the QUERY with the UNION's and then refer to that VIEW with the SELECT TOP 3...
*** Read the sticky in the DB forum about how to get your question answered quickly!! ***
Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".
"select pontosind1 as Totais, classifind1 as Classifind, seccao1 as Secção, classe1 as Classe, designacao1 as Designação, nomesocio as Expositor, anilha1 as Anilha, gaiolaind1 as Gaiola, Sexo1 as Sexo" & _
yes you are right...now the code work,but the "top 3" don't extract the desired values because the top 3 extract only 3 recordsets and not all the 3 big recordsets....strange!!!!!!!
Can you see the project attached,and run it,and change the top 3 for top 10?
But you are ordering by the CLASS DESCRIPTION - right? So you are getting the alphabetically first 3 classes - is that what is happening?
yes that correct...I get the first 3 classes alphabetically
Don't you want the 3-highest grades?
yes I want the highest 3 grades but ordering by classe and totais...I want the 3 highest values ordering by classe and listening by totais....but the 3 highest values should be By totais not classe
Maybe like this,but the sort are not right,unless the syntax are not correct
VB Code:
sql1 = "Select Top 3 * From ( " & _
"select pontosind1 as Totais, classifind1 as Classifind, seccao1 as Secção, classe1 as Classe, designacao1 as Designação, nomesocio as Expositor, anilha1 as Anilha, gaiolaind1 as Gaiola, Sexo1 as Sexo" & _