Home > Archive > PHP Language > August 2005 > query translation
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
| gniewosh 2005-08-13, 8:59 am |
| Hi,
I'm trying to translate from mysql to pgsql one query as below
SELECT DISTINCT name FROM table ORDER BY surname
Referring to mysql this query was working perfectly, however when I try use
this query with pgsql I didn't achieve result
What should I do?
Why that query doesn't work correctly with pgsql?
thanks in advance
| |
| Simon Stienen 2005-08-13, 4:59 pm |
| On 2005-08-13 15-57-29 gniewosh <news@inso.pl> wrote:
> SELECT DISTINCT name FROM table ORDER BY surname
This should be a solution for THIS case:
SELECT name FROM table ORDER BY surname GROUP BY name
> Why that query doesn't work correctly with pgsql?
I'm not in Pg, so I am unable to answer this question, sorry. For the same
reason, you should be careful with the solution I posted above, since there
might be a much better solution.
HTH (at least a little),
Simon
--
Simon Stienen <http://slashlife.org/>
"What you do in this world is a matter of no consequence,
The question is, what can you make people believe that you have done."
/Sherlock Holmes in A Study in Scarlet by Sir Arthur Conan Doyle/
| |
| gniewosh 2005-08-13, 9:59 pm |
| > This should be a solution for THIS case:
> SELECT name FROM table ORDER BY surname GROUP BY name
unfortunatelly this solution also doesn't work :(
I prepared special script in php, which is removing the repeat record.
thanks for your help
| |
|
| On Sat, 13 Aug 2005 15:57:29 +0200, gniewosh wrote:
>I'm trying to translate from mysql to pgsql one query as below
>SELECT DISTINCT name FROM table ORDER BY surname
>Referring to mysql this query was working perfectly, however when I try use
>this query with pgsql I didn't achieve result
>Why that query doesn't work correctly with pgsql?
I don't know pgsql either but try:
SELECT DISTINCT table.name FROM table ORDER BY surname
or
SELECT table.name, table.surname FROM table ORDER BY table.surname
or even
SELECT name, surname FROM table ORDER BY surname
It may be simply that you need to include "surnname" in your SELECT.
Adam.
| |
| gniewosh 2005-08-14, 3:59 am |
| Adam,
> SELECT DISTINCT table.name FROM table ORDER BY surname
the first query doesn't work :(
> SELECT table.name, table.surname FROM table ORDER BY table.surname
> SELECT name, surname FROM table ORDER BY surname
The second and third even they are working they don't give me answers as I
want.
I would like to segregate particular records from one column according to
order in second column as I wrote before.
| |
| Simon Stienen 2005-08-14, 3:59 am |
| On 2005-08-14 08-26-52 Adam <anon@nowhere.com> wrote:
> SELECT table.name, table.surname FROM table ORDER BY table.surname
> SELECT name, surname FROM table ORDER BY surname
JFYI:
SELECT name FROM foo;
+--------+
| name |
+--------+
| Monica |
| Monica |
| Peter |
| Monica |
| Anne |
| Peter |
+--------+
SELECT DISTINCT name FROM foo;
+--------+
| name |
+--------+
| Monica |
| Peter |
| Anne |
+--------+
You can't archive this by just adding the surname to the result.
HTH,
Simon
--
Simon Stienen <http://slashlife.org/>
"What you do in this world is a matter of no consequence,
The question is, what can you make people believe that you have done."
/Sherlock Holmes in A Study in Scarlet by Sir Arthur Conan Doyle/
|
|
|
|
|