SELECT
am 11.12.2005 02:04:28 von Ron Piggott
I am trying to put together a SELECT syntax. I am querying a response
database and I only want to obtain each user's name once even if they
have given more than 1 response.
$query="SELECT * FROM conversation_table WHERE conversation_reference =
$conversation_currently_displayed";
$response_created_by = mysql_result($result,$i,"response_created_by");
My ideal is that if users 1, 2, 4 & 5 are in dialogue with each other
the above SELECT $query will only give the results of their identity
once with the mysql_request() function
Thanks for your help.
Ron
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: SELECT
am 11.12.2005 02:20:02 von Philip Hallstrom
> I am trying to put together a SELECT syntax. I am querying a response
> database and I only want to obtain each user's name once even if they
> have given more than 1 response.
>
> $query="SELECT * FROM conversation_table WHERE conversation_reference =
> $conversation_currently_displayed";
>
> $response_created_by = mysql_result($result,$i,"response_created_by");
>
> My ideal is that if users 1, 2, 4 & 5 are in dialogue with each other
> the above SELECT $query will only give the results of their identity
> once with the mysql_request() function
SELECT DISTINCT(user_id) FROM conversation_table WHERE
conversation_reference = $conversation_currently_displayed
should do it.
-philip
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: SELECT
am 11.12.2005 03:01:43 von Julien Bonastre
Have you considered the GROUP BY statement of SQL??
For example if this is a table's data:
msg_id user varname value
2 1 yada hello
3 1 yada hows it going?
4 2 yada its me! Zonk!
6 1 turmoil anyone here seen that movie
before?
8 2 turmoil oh yeah, years back!
9 1 yada and that means??
you can:
$request_varname="yada";
SELECT * FROM the_table WHERE varname = "$request_varname" GROUP BY user
HAVING max(msg_id)
If I can recreate my "in brain" SQL engine correctly this sql should work..
I'm not sure of exactly what your setup is like relating to storage of the
data, and I'm not certain I understand what you are trying to retrieve with
your query either, but I hope I'm heading down the right track..
I'm sure either way that its the GROUP BY predicate you are after..
enjoy!~
---oOo--- Allowing users to execute CGI scripts in any directory should only
be considered if: ... a.. You have no users, and nobody ever visits your
server. ... Extracted Quote: Security Tips - Apache HTTP
Server ---oOo--- ------oOo---------------oOo------ Julien Bonastre
[The_RadiX] The-Spectrum Network CEO ABN: 64 235 749 494
julien@the-spectrum.org
www.the-spectrum.org ------oOo---------------oOo------
----- Original Message -----
From: "Ron Piggott (PHP)"
To: "PHP DB"
Sent: Sunday, December 11, 2005 11:04 AM
Subject: [PHP-DB] SELECT
>I am trying to put together a SELECT syntax. I am querying a response
> database and I only want to obtain each user's name once even if they
> have given more than 1 response.
>
> $query="SELECT * FROM conversation_table WHERE conversation_reference =
> $conversation_currently_displayed";
>
> $response_created_by = mysql_result($result,$i,"response_created_by");
>
> My ideal is that if users 1, 2, 4 & 5 are in dialogue with each other
> the above SELECT $query will only give the results of their identity
> once with the mysql_request() function
>
> Thanks for your help.
>
> Ron
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: SELECT
am 11.12.2005 03:04:56 von Julien Bonastre
Yes, DISTINCT will do the same trick, I wasn't sure though as in the context
he placed it I reconsidered DISTINCT and thought of GROUP BY because where
there may be multiple entries/rows relating to a shared field they would
obviously be seperated by perhaps a unique primary key, timestamp, id of
some form, you know what i mean? And most likely obviously this field would
be a unique field to the table, or at least to that group of rows.. And
again, likely it would be time/date controlled, as in a incremental id
number, or timestamp etc..
So in that case he may want the latest row??
Again as I've said in previous email, I'm not really sure what he was
wanting to do with the query, did he want a particular row? or any row..
Anyway, thats my 5 cents...
---oOo--- Allowing users to execute CGI scripts in any directory should only
be considered if: ... a.. You have no users, and nobody ever visits your
server. ... Extracted Quote: Security Tips - Apache HTTP
Server ---oOo--- ------oOo---------------oOo------ Julien Bonastre
[The_RadiX] The-Spectrum Network CEO ABN: 64 235 749 494
julien@the-spectrum.org
www.the-spectrum.org ------oOo---------------oOo------
----- Original Message -----
From: "Philip Hallstrom"
To: "Ron Piggott (PHP)"
Cc: "PHP DB"
Sent: Sunday, December 11, 2005 11:20 AM
Subject: Re: [PHP-DB] SELECT
>> I am trying to put together a SELECT syntax. I am querying a response
>> database and I only want to obtain each user's name once even if they
>> have given more than 1 response.
>>
>> $query="SELECT * FROM conversation_table WHERE conversation_reference =
>> $conversation_currently_displayed";
>>
>> $response_created_by = mysql_result($result,$i,"response_created_by");
>>
>> My ideal is that if users 1, 2, 4 & 5 are in dialogue with each other
>> the above SELECT $query will only give the results of their identity
>> once with the mysql_request() function
>
> SELECT DISTINCT(user_id) FROM conversation_table WHERE
> conversation_reference = $conversation_currently_displayed
>
> should do it.
>
> -philip
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php