CodeCharge Studio
search Register Login  

Visual PHP Web Development

Visually Create Internationalized Web Applications, Web Reports, Calendars, and more.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> PHP

 order based on count()

Print topic Send  topic

Author Message
Walter M
Posted: 10/20/2005, 10:21 PM

I need to order the "questions" based on the nomber of "answers" they have, but they are in different tables.

I know how to count, based in this post: http://forums.codecharge.com/posts.php?post_id=42323

But, how can I order my questions, based in the number of answers they have?

thanks in advance,
Walter Kempees
Posted: 10/21/2005, 4:13 AM

That example is based on counting in the form/grid, in other words counting
after the fact.

You soilution would be to use VQB build up a joined SQL over the two tables,
counting in the process and returning the count() result as a field in the
result.
You could the n do an order by in the same select, probably depending on DB
used.

When returning fields from the database to the grid, they can be made
sortable.

Hope this is clear enough

select t.1f1 as field1, count(t2.f1) as field 2
from table1 as t1
left join table2 as t2 on t1.fx = t2.fx
order by field2

Walter ;-)

<WalterM@forum.codecharge (Walter M)> schreef in bericht
news:543587abfdd7e3@news.codecharge.com...
>I need to order the "questions" based on the nomber of "answers" they have,
>but
> they are in different tables.
>
> I know how to count, based in this post:
> http://forums.codecharge.com/posts.php?post_id=42323
>
> But, how can I order my questions, based in the number of answers they
> have?
>
> thanks in advance,
> ---------------------------------------
> Sent from YesSoftware forum
> http://forums.codecharge.com/
>

Walter Kempees
Posted: 10/21/2005, 4:26 AM

or even better

select t1.f1 as field1, count(t2.f1) as field 2
from table1 as t1
left join table2 as t2 on t1.fx = t2.fx
group by t1.f1
order by field2

fx is short for the 'x' field from t1 and t2 that connect the two


"Walter Kempees" <kempe819@planet.nl> schreef in bericht
news:djaih0$jk$1@news.codecharge.com...
> That example is based on counting in the form/grid, in other words
> counting after the fact.
>
> You soilution would be to use VQB build up a joined SQL over the two
> tables, counting in the process and returning the count() result as a
> field in the result.
> You could the n do an order by in the same select, probably depending on
> DB used.
>
> When returning fields from the database to the grid, they can be made
> sortable.
>
> Hope this is clear enough
>
> select t.1f1 as field1, count(t2.f1) as field 2
> from table1 as t1
> left join table2 as t2 on t1.fx = t2.fx
> order by field2
>
> Walter ;-)
>
> <WalterM@forum.codecharge (Walter M)> schreef in bericht
>news:543587abfdd7e3@news.codecharge.com...
>>I need to order the "questions" based on the nomber of "answers" they
>>have, but
>> they are in different tables.
>>
>> I know how to count, based in this post:
>> http://forums.codecharge.com/posts.php?post_id=42323
>>
>> But, how can I order my questions, based in the number of answers they
>> have?
>>
>> thanks in advance,
>> ---------------------------------------
>> Sent from YesSoftware forum
>> http://forums.codecharge.com/
>>
>
>

Damian Hupfeld
Posted: 10/21/2005, 4:42 AM

You love writing these sql queries dont you!

"Walter Kempees" <kempe819@planet.nl> wrote in message
news:djaj8b$tf$1@news.codecharge.com...
> or even better
>
> select t1.f1 as field1, count(t2.f1) as field 2
> from table1 as t1
> left join table2 as t2 on t1.fx = t2.fx
> group by t1.f1
> order by field2
>
> fx is short for the 'x' field from t1 and t2 that connect the two
>
>
> "Walter Kempees" <kempe819@planet.nl> schreef in bericht
>news:djaih0$jk$1@news.codecharge.com...
>> That example is based on counting in the form/grid, in other words
>> counting after the fact.
>>
>> You soilution would be to use VQB build up a joined SQL over the two
>> tables, counting in the process and returning the count() result as a
>> field in the result.
>> You could the n do an order by in the same select, probably depending on
>> DB used.
>>
>> When returning fields from the database to the grid, they can be made
>> sortable.
>>
>> Hope this is clear enough
>>
>> select t.1f1 as field1, count(t2.f1) as field 2
>> from table1 as t1
>> left join table2 as t2 on t1.fx = t2.fx
>> order by field2
>>
>> Walter ;-)
>>
>> <WalterM@forum.codecharge (Walter M)> schreef in bericht
>>news:543587abfdd7e3@news.codecharge.com...
>>>I need to order the "questions" based on the nomber of "answers" they
>>>have, but
>>> they are in different tables.
>>>
>>> I know how to count, based in this post:
>>> http://forums.codecharge.com/posts.php?post_id=42323
>>>
>>> But, how can I order my questions, based in the number of answers they
>>> have?
>>>
>>> thanks in advance,
>>> ---------------------------------------
>>> Sent from YesSoftware forum
>>> http://forums.codecharge.com/
>>>
>>
>>
>
>

Walter Kempees
Posted: 10/21/2005, 5:03 AM

yep, that's my main trade

"Damian Hupfeld" <damian.hupfeld@itng.com.au> schreef in bericht
news:djak78$18u$1@news.codecharge.com...
> You love writing these sql queries dont you!
>
> "Walter Kempees" <kempe819@planet.nl> wrote in message
>news:djaj8b$tf$1@news.codecharge.com...
>> or even better
>>
>> select t1.f1 as field1, count(t2.f1) as field 2
>> from table1 as t1
>> left join table2 as t2 on t1.fx = t2.fx
>> group by t1.f1
>> order by field2
>>
>> fx is short for the 'x' field from t1 and t2 that connect the two
>>
>>
>> "Walter Kempees" <kempe819@planet.nl> schreef in bericht
>>news:djaih0$jk$1@news.codecharge.com...
>>> That example is based on counting in the form/grid, in other words
>>> counting after the fact.
>>>
>>> You soilution would be to use VQB build up a joined SQL over the two
>>> tables, counting in the process and returning the count() result as a
>>> field in the result.
>>> You could the n do an order by in the same select, probably depending on
>>> DB used.
>>>
>>> When returning fields from the database to the grid, they can be made
>>> sortable.
>>>
>>> Hope this is clear enough
>>>
>>> select t.1f1 as field1, count(t2.f1) as field 2
>>> from table1 as t1
>>> left join table2 as t2 on t1.fx = t2.fx
>>> order by field2
>>>
>>> Walter ;-)
>>>
>>> <WalterM@forum.codecharge (Walter M)> schreef in bericht
>>>news:543587abfdd7e3@news.codecharge.com...
>>>>I need to order the "questions" based on the nomber of "answers" they
>>>>have, but
>>>> they are in different tables.
>>>>
>>>> I know how to count, based in this post:
>>>> http://forums.codecharge.com/posts.php?post_id=42323
>>>>
>>>> But, how can I order my questions, based in the number of answers they
>>>> have?
>>>>
>>>> thanks in advance,
>>>> ---------------------------------------
>>>> Sent from YesSoftware forum
>>>> http://forums.codecharge.com/
>>>>
>>>
>>>
>>
>>
>
>

chris
Posted: 10/21/2005, 9:40 AM

Good!!

perhaps you can help me
How can I pass a variable from a grid - please see my post passing data from
1 grid to another

I'd appreciate any help


"Damian Hupfeld" <damian.hupfeld@itng.com.au> wrote in message
news:djak78$18u$1@news.codecharge.com...
> You love writing these sql queries dont you!
>
> "Walter Kempees" <kempe819@planet.nl> wrote in message
>news:djaj8b$tf$1@news.codecharge.com...
> > or even better
> >
> > select t1.f1 as field1, count(t2.f1) as field 2
> > from table1 as t1
> > left join table2 as t2 on t1.fx = t2.fx
> > group by t1.f1
> > order by field2
> >
> > fx is short for the 'x' field from t1 and t2 that connect the two
> >
> >
> > "Walter Kempees" <kempe819@planet.nl> schreef in bericht
> >news:djaih0$jk$1@news.codecharge.com...
> >> That example is based on counting in the form/grid, in other words
> >> counting after the fact.
> >>
> >> You soilution would be to use VQB build up a joined SQL over the two
> >> tables, counting in the process and returning the count() result as a
> >> field in the result.
> >> You could the n do an order by in the same select, probably depending
on
> >> DB used.
> >>
> >> When returning fields from the database to the grid, they can be made
> >> sortable.
> >>
> >> Hope this is clear enough
> >>
> >> select t.1f1 as field1, count(t2.f1) as field 2
> >> from table1 as t1
> >> left join table2 as t2 on t1.fx = t2.fx
> >> order by field2
> >>
> >> Walter ;-)
> >>
> >> <WalterM@forum.codecharge (Walter M)> schreef in bericht
> >>news:543587abfdd7e3@news.codecharge.com...
> >>>I need to order the "questions" based on the nomber of "answers" they
> >>>have, but
> >>> they are in different tables.
> >>>
> >>> I know how to count, based in this post:
> >>> http://forums.codecharge.com/posts.php?post_id=42323
> >>>
> >>> But, how can I order my questions, based in the number of answers they
> >>> have?
> >>>
> >>> thanks in advance,
> >>> ---------------------------------------
> >>> Sent from YesSoftware forum
> >>> http://forums.codecharge.com/
> >>>
> >>
> >>
> >
> >
>
>


Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

Internet Database

Visually create Web enabled database applications in minutes.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.