Subject Re: [firebird-support] Re: Problem with LEFT OUTER JOIN and COUNT()
Author Fabio Gomes
So simple ^^

Thanx a lot man, this did the trick:

SELECT COUNT(DISTINCT N.CUPOM)

Cause N.CUPOM is my primary key, and thats all that matters :)


On 4/10/06, Svein Erling Tysvær <svein.erling.tysvaer@...>
wrote:
>
> Try
>
> SELECT COUNT(DISTINCT N.EMISSAO||N.CUPOM||N.OBS1||N.OBS3||V.DESCRICAO)
>
> FROM SIAD_VND N
> LEFT OUTER JOIN SIAD_VED V ON (V.CODIGO = N.VEDEXT)
> WHERE TIPO='V' AND N.OBS3 LIKE '%SUS%'
>
> You will probably have to tweak this a bit depending on the values in
> STAD_VND - e.g. N.EMISSAO = 'Fabio' and N.CUPOM = '' would be
> considered equal to N.EMISSAO = 'Fa' and N.CUPOM = 'bio' in the query
> above and only counted once.
>
> SELECT DISTINCT COUNT(*) doesn't count distinct values, it makes sure
> that the number of rows is returned only once (something your query
> does anyway)!
>
> HTH,
> Set
>
>
> --- In firebird-support@yahoogroups.com, "Fabio Gomes" wrote:
> >
> > Hi guys,
> >
> > I have a pagination function in php that uses a counter to generate
> > the page links and stuff, it always worked fine, but i m having a
> > problem with this query:
> >
> > I m using this to count the results:
> >
> > SELECT DISTINCT COUNT(*)
> > FROM SIAD_VND N
> > LEFT OUTER JOIN SIAD_VED V ON (V.CODIGO = N.VEDEXT)
> > WHERE TIPO='V' AND N.OBS3 LIKE '%SUS%'
> >
> > And this to show them:
> >
> > SELECT DISTINCT N.EMISSAO, N.CUPOM, N.OBS1, N.OBS3, V.DESCRICAO
> > FROM SIAD_VND N
> > LEFT OUTER JOIN SIAD_VED V ON (V.CODIGO = N.VEDEXT)
> > WHERE TIPO='V' AND N.OBS3 LIKE '%SUS%'
> >
> >
> > But the problem is that the COUNT() returns me 2000+ rows, and the
> > query return just 1000, i tried to change the query and stuff. but
> > it isnt working, i think that it have something to do with the LEFT
> > OUTER JOIN.
> >
> > Am i doing something wrong?
> >
> > Anyway, any help is welcome.
> >
> > Thanx,
> >
> > -Fábio.
>
>
>
>
>
>
>
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>
> Visit http://firebird.sourceforge.net and click the Resources item
> on the main (top) menu. Try Knowledgebase and FAQ links !
>
> Also search the knowledgebases at http://www.ibphoenix.com
>
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>
>
>
> ------------------------------
> YAHOO! GROUPS LINKS
>
>
> - Visit your group "firebird-support<http://groups.yahoo.com/group/firebird-support>"
> on the web.
>
> - To unsubscribe from this group, send an email to:
> firebird-support-unsubscribe@yahoogroups.com<firebird-support-unsubscribe@yahoogroups.com?subject=Unsubscribe>
>
> - Your use of Yahoo! Groups is subject to the Yahoo! Terms of
> Service <http://docs.yahoo.com/info/terms/>.
>
>
> ------------------------------
>


[Non-text portions of this message have been removed]