|
|
|
![]() |
|
Strumenti |
![]() |
#1 |
Member
Iscritto dal: Apr 2004
Città: Vicenza
Messaggi: 123
|
[SQL] First e Last
Codice:
query SQL: SELECT FIRST ( img ) AS I FROM blog LIMIT 0 , 30 Messaggio di MySQL: #1064 - You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '( img ) AS I from blog LIMIT 0, 30' at line 1 FIRST(column) Returns the value of the first record in a specified field (not supported in SQLServer2K) LAST(column) Returns the value of the last record in a specified field (not supported in SQLServer2K) Qualcuno mi aiuta a capire cosa non va?
__________________
Love, let me sleep tonight on your couch And remember the smell of the fabric of your simple city dress [Jeff Buckley - So real] |
![]() |
![]() |
![]() |
#2 |
Member
Iscritto dal: Oct 2005
Messaggi: 115
|
Non c'è la GROUP BY.
First() e Last() sono funzioni di aggregazione. ESEMPIO: ho tre record: Codice:
ID - NOME 1 - mario 2 - giuseppe 3 - mario restituisce 1 - Mario 2 - Giuseppe Se invece avessi usato SELECT Last(ID) FROM tabella GROUP BY NOME 3 - Mario 2 - Giuseppe Infine SELECT Sum(ID) FROM tabella GROUP BY NOME 4 - Mario 2 - Giuseppe PS: Nota bene First() restituisce il primo record incontrato nel raggruppamento, indipendentemente dal suo ordine. Ad esempio se per qualche motivo, fisicamente il DBMS incontra prima l'id 4 e poi il 2, restituisce 4. Min() invece restituisce il minimo ordinato. Last() e Max() stesse considerazioni |
![]() |
![]() |
![]() |
#3 | |
Senior Member
Iscritto dal: Apr 2000
Città: Vicino a Montecatini(Pistoia) Moto:Kawasaki Ninja ZX-9R Scudetti: 29
Messaggi: 53971
|
Quote:
![]() |
|
![]() |
![]() |
![]() |
#4 |
Member
Iscritto dal: Apr 2004
Città: Vicenza
Messaggi: 123
|
Select Last(id) from blog group by user
tabella blog: id 1 user pippo id 2 user gianni id 3 user gianni #1064 - You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '( id ) from blog group by user LIMIT 0, 30' at line 1 Anche prima usavo group by ma non l'avevo riportato perchè ho fatto copia e incolla e non mi sono accorto della mancanza. Sto seguendo qua: http://dev.mysql.com/doc/mysql/en Uso MySql di Aruba. ![]() p.s. Questo funziona: Select max(id) from blog GROUP by user
__________________
Love, let me sleep tonight on your couch And remember the smell of the fabric of your simple city dress [Jeff Buckley - So real] Ultima modifica di breiko : 04-11-2005 alle 18:10. |
![]() |
![]() |
![]() |
#5 |
Senior Member
Iscritto dal: Apr 2000
Città: Vicino a Montecatini(Pistoia) Moto:Kawasaki Ninja ZX-9R Scudetti: 29
Messaggi: 53971
|
Io sto parlando di quelle due righe ti ho quotato...dove hai trovato quelle definizioni ?
|
![]() |
![]() |
![]() |
#6 |
Member
Iscritto dal: Oct 2005
Messaggi: 115
|
effettivamente "AS I" è una particolarità di SQL 2000, non so se MySql la supporta...
|
![]() |
![]() |
![]() |
#7 | |
Member
Iscritto dal: Apr 2004
Città: Vicenza
Messaggi: 123
|
Quote:
http://www.w3schools.com/sql/sql_functions.asp
__________________
Love, let me sleep tonight on your couch And remember the smell of the fabric of your simple city dress [Jeff Buckley - So real] |
|
![]() |
![]() |
![]() |
#8 | |
Member
Iscritto dal: Oct 2005
Messaggi: 115
|
Quote:
Sicuramente MySQL non supporta Last() |
|
![]() |
![]() |
![]() |
#9 | |
Member
Iscritto dal: Apr 2004
Città: Vicenza
Messaggi: 123
|
Quote:
![]() Mo come faccio? Mission impossible..
__________________
Love, let me sleep tonight on your couch And remember the smell of the fabric of your simple city dress [Jeff Buckley - So real] |
|
![]() |
![]() |
![]() |
#10 |
Member
Iscritto dal: Oct 2005
Messaggi: 115
|
Ma che devi fare ????
|
![]() |
![]() |
![]() |
#11 |
Member
Iscritto dal: Apr 2004
Città: Vicenza
Messaggi: 123
|
tabella blog:
id 1 immagine A user Pippo id 2 immagine B user Gianni id 3 immagine C user Pippo A me serve avere l'ultima Immagine inserita da Pippo. Siccome la colonna immagine non ha un ordine non posso dire max(immagine) dovrei usare last(immagine). Quindi: SELECT user,max(id) as I,immagine FROM blog GROUP BY user ORDER BY I DESC non mi seziona l'immagine C ma l'immagine A. Precisamente: Pippo 3 A (io voglio Pippo 3 C) Dovrei quindi usare last(img) ma non funziona..
__________________
Love, let me sleep tonight on your couch And remember the smell of the fabric of your simple city dress [Jeff Buckley - So real] |
![]() |
![]() |
![]() |
#12 |
Member
Iscritto dal: Oct 2005
Messaggi: 115
|
SELECT * FROM Blog INNER JOIN (SELECT Max(Id),User FROM blog GROUP BY User) AS Temp ON Blog.Id = Temp.Id
|
![]() |
![]() |
![]() |
#13 |
Member
Iscritto dal: Apr 2004
Città: Vicenza
Messaggi: 123
|
You have an error in your SQL syntax.
Sei sicuro di quel Select all'interno del JOIN? Anzi del select all'interno del FROM che sembra non possa funzionare..
__________________
Love, let me sleep tonight on your couch And remember the smell of the fabric of your simple city dress [Jeff Buckley - So real] Ultima modifica di breiko : 05-11-2005 alle 12:57. |
![]() |
![]() |
![]() |
Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 11:16.