[mysql] eerste regel uit rits rows

Pagina: 1
Acties:
  • 36 views sinds 30-01-2008

  • hobbeldebobbel
  • Registratie: Februari 2001
  • Laatst online: 15-02-2023
deze sql queryheb ik.... en nu spuugt ie natuurlijk een 'tabel' uit met daarin alle klachten (het gaatom een klachten registratie iets) uit met een bepaalde klacht id.
opbouw tabel:
ID | klacht_id | actie | user | datum

nou wil ik voor een soort van overzichtje enkel de laatste toevoeging van de tabel weergeven... dus; als ik deze query draai:

PHP:
1
2
$klachtid = 2;
$sql2 = "SELECT * FROM bob_acties WHERE klacht_id='$klachtid' ORDER BY datum ASC";


de bovenste row :)

alleen hoe krijg ik alleen de bovenste row.
Ik kan alles in een array stoppen:
PHP:
1
2
$result_actie = mysql_query($sql2,$db);
 $actierow = mysql_fetch_array($result_actie);


is dit een goede oplossing? aangezien ik eigenlijk in mn sql query alles selecteer... is er een sql query waarbij ik enkel de bovenste row selecteer??? of is het tweede stukje php goed?

[ Voor 3% gewijzigd door hobbeldebobbel op 27-12-2003 16:41 ]

hier zou een slimme opmerking kunnen staan
maar die staat er niet


  • creative8500
  • Registratie: September 2001
  • Laatst online: 03-01 16:54

creative8500

freedom.

The LIMIT clause can be used to constrain the number of rows returned by the SELECT statement. LIMIT takes one or two numeric arguments, which must be integer constants. With one argument, the value specifies the number of rows to return from the beginning of the result set. With two arguments, the first specifies the offset of the first row to return, the second specifies the maximum number of rows to return. The offset of the initial row is 0 (not 1): To be compatible with PostgreSQL MySQL also supports the syntax: LIMIT row_count OFFSET offset.

mysql> SELECT * FROM table LIMIT 5,10; # Retrieve rows 6-15

To retrieve all rows from a certain offset up to the end of the result set, you can use some big number for the second parameter:

mysql> SELECT * FROM table LIMIT 95,18446744073709551615; # Retrieve rows 96-last.

If one argument is given, it indicates the maximum number of rows to return:

mysql> SELECT * FROM table LIMIT 5; # Retrieve first 5 rows

In other words, LIMIT n is equivalent to LIMIT 0,n.

  • hobbeldebobbel
  • Registratie: Februari 2001
  • Laatst online: 15-02-2023
ok thanx... :)

hier zou een slimme opmerking kunnen staan
maar die staat er niet


  • drm
  • Registratie: Februari 2001
  • Laatst online: 09-06-2025

drm

f0pc0dert

Dit je had je zelf met een beetje inspanning ook wel kunnen vinden...

Music is the pleasure the human mind experiences from counting without being aware that it is counting
~ Gottfried Leibniz


Dit topic is gesloten.