PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.databases.mysql > top3 with or without "having" in query
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
top3 with or without "having" in query

Réponse
 
LinkBack Outils de la discussion
Vieux 21/09/2007, 09h52   #1
Kim Slot
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut top3 with or without "having" in query

Which is faster and easier ?

I have a table with messages from users. I want to fetch top3 users
whom have sent most messages and more than X (X being a number).
User data, such as name and id are stored in another table.

A) add a new field in table_users to hold the total number of messages
sent (like "messages_total"), and then when querying for top3 it will
look something like this: "SELECT id.table_users, name.table_users,
COUNT(*.table_messages) FROM table_users, table_messages WHERE
messages_total.table_users >= X ORDER BY DESC LIMIT 3"
This should also allow users to delete messages while keeping their
total count.

B) use the term 'having' in the query to avoid having the extra field
("messages_total") in the user table. I think this is how the query
will look like: "SELECT id.table_users, name.table_users,
COUNT(*.table_messages) FROM table_users, table_messages HAVING
messages_total.table_users >= X ORDER BY DESC LIMIT 3"

C) something else ?

  Réponse avec citation
Vieux 21/09/2007, 12h01   #2
Paul Lautman
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: top3 with or without "having" in query

Kim Slot wrote:
> Which is faster and easier ?
>
> I have a table with messages from users. I want to fetch top3 users
> whom have sent most messages and more than X (X being a number).
> User data, such as name and id are stored in another table.
>
> A) add a new field in table_users to hold the total number of messages
> sent (like "messages_total"), and then when querying for top3 it will
> look something like this: "SELECT id.table_users, name.table_users,
> COUNT(*.table_messages) FROM table_users, table_messages WHERE
> messages_total.table_users >= X ORDER BY DESC LIMIT 3"
> This should also allow users to delete messages while keeping their
> total count.
>
> B) use the term 'having' in the query to avoid having the extra field
> ("messages_total") in the user table. I think this is how the query
> will look like: "SELECT id.table_users, name.table_users,
> COUNT(*.table_messages) FROM table_users, table_messages HAVING
> messages_total.table_users >= X ORDER BY DESC LIMIT 3"
>
> C) something else ?


Easier? That is down to which one you find easier!

Faster? Time both of them and you will find out!


  Réponse avec citation
Vieux 24/09/2007, 11h12   #3
Kim
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: top3 with or without "having" in query

On Sep 21, 1:01 pm, "Paul Lautman" <paul.laut...@btinternet.com>
wrote:
> Kim Slot wrote:
> > Which is faster and easier ?

>
> > I have a table with messages from users. I want to fetch top3 users
> > whom have sent most messages and more than X (X being a number).
> > User data, such as name and id are stored in another table.

>
> > A) add a new field in table_users to hold the total number of messages
> > sent (like "messages_total"), and then when querying for top3 it will
> > look something like this: "SELECT id.table_users, name.table_users,
> > COUNT(*.table_messages) FROM table_users, table_messages WHERE
> > messages_total.table_users >= X ORDER BY DESC LIMIT 3"
> > This should also allow users to delete messages while keeping their
> > total count.

>
> > B) use the term 'having' in the query to avoid having the extra field
> > ("messages_total") in the user table. I think this is how the query
> > will look like: "SELECT id.table_users, name.table_users,
> > COUNT(*.table_messages) FROM table_users, table_messages HAVING
> > messages_total.table_users >= X ORDER BY DESC LIMIT 3"

>
> > C) something else ?

>
> Easier? That is down to which one you find easier!
>
> Faster? Time both of them and you will find out!


That clearly wasnt the answer I hoped for.
If I could test it, then I would have done so instead of asking.

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 23h08.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,09447 seconds with 11 queries