mysql question.

mysql question.

am 03.04.2007 12:20:45 von Me2resh Lists

------=_Part_5974_6976316.1175595645992
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

hi
i need help regarding a sql query in my php app.

the query is :
$SQL = "SELECT DISTINCT(EMail) FROM mena_guests WHERE Voted = 'yes'
LIMIT $startingID,$items_numbers_list";

i want to sort this query by the number of the repeated EMail counts.
can anyone help me with that please ?

------=_Part_5974_6976316.1175595645992--

Re: mysql question.

am 03.04.2007 15:20:11 von Dimiter Ivanov

On 4/3/07, Me2resh Lists wrote:
> hi
> i need help regarding a sql query in my php app.
>
> the query is :
> $SQL = "SELECT DISTINCT(EMail) FROM mena_guests WHERE Voted = 'yes'
> LIMIT $startingID,$items_numbers_list";
>
> i want to sort this query by the number of the repeated EMail counts.
> can anyone help me with that please ?
>

$SQL = "SELECT EMail,count(EMail) AS repeated FROM mena_guests WHERE
Voted = 'yes' GROUP BY EMail ORDER BY count(EMail) LIMIT
$startingID,$items_numbers_list";

I can't remember if in the order clause you can order by the alias of
the field or using the count again, test it to see what's the proper
syntax

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: mysql question.

am 03.04.2007 19:41:13 von Haydar TUNA

Hello,
I try your SQL statements. There is no problem on your SQL syntax
and you can use alias in the order by clause.:)

$SQL = "SELECT EMail,count(EMail) AS repeated FROM mena_guests WHERE
Voted = 'yes' GROUP BY EMail ORDER BY repeated LIMIT
$startingID,$items_numbers_list";


--
Republic Of Turkey - Ministry of National Education
Education Technology Department Ankara / TURKEY
Web: http://www.haydartuna.net

""Dimiter Ivanov"" , haber iletisinde sunlari
yazdi:7cc8007f0704030620n7a6fd383qe6ffa5d5437b2ec7@mail.gmai l.com...
> On 4/3/07, Me2resh Lists wrote:
>> hi
>> i need help regarding a sql query in my php app.
>>
>> the query is :
>> $SQL = "SELECT DISTINCT(EMail) FROM mena_guests WHERE Voted = 'yes'
>> LIMIT $startingID,$items_numbers_list";
>>
>> i want to sort this query by the number of the repeated EMail counts.
>> can anyone help me with that please ?
>>
>
> $SQL = "SELECT EMail,count(EMail) AS repeated FROM mena_guests WHERE
> Voted = 'yes' GROUP BY EMail ORDER BY count(EMail) LIMIT
> $startingID,$items_numbers_list";
>
> I can't remember if in the order clause you can order by the alias of
> the field or using the count again, test it to see what's the proper
> syntax

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: mysql question.

am 03.04.2007 22:23:47 von Dan Luevano

Me2resh Lists,

with my limited SQL experience it appears that you're asking to sort the
query without the proper results from the query. Your SELECT statement
below should return the following:

Non-duplicate rows of mena_guests.EMail where mena_guests.Voted is yes,
starting at $startingID up to $items_numbers_list records.

Since the DISTINCT clause is used, only non-duplicate records are
returned, and there is no count of the rows duplicated for each distinct
EMail. Thus you can't sort the result by any count. I think the select
statement that you really want is this...

SELECT EMail, COUNT(*) FROM mena_guests WHERE Voted = 'yes' GROUP BY
EMail LIMIT $startingID, $items_numbers_list


The "group by" will cause the DISTINCT effect AND you'll be able to see
how many duplicates there were for each distinct EMail.

Hope this helps,

Dan Luevano

php-db-digest-help@lists.php.net wrote:
>
> mysql question.
> 43402 by: Me2resh Lists
>
> hi
>
> i need help regarding a sql query in my php app.
>
>
>
> the query is :
>
> $SQL = "SELECT DISTINCT(EMail) FROM mena_guests WHERE Voted = 'yes'
>
> LIMIT $startingID,$items_numbers_list";
>
>
>
> i want to sort this query by the number of the repeated EMail counts.
>
> can anyone help me with that please ?
>
>
> ------------------------------------------------------------ ----------
>

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php