Jump to content

[SOLVED] Selecting last element


peddel

Recommended Posts

Is there a way to alter my query so that i dont get 100-200 records, but directly the last made entry.

 

Maybe a variant on the limit option?

 

SELECT test.tag, test.waarde
FROM registratie 
LEFT JOIN test ON registratie.registratieID = test.registratieID
LEFT JOIN oorsprong_gegevens ON registratie.oorsprong = oorsprong_gegevens.oorsprong
WHERE registratie.productieregister = '1'
AND test.tag='EF1';

Link to comment
https://forums.phpfreaks.com/topic/143742-solved-selecting-last-element/
Share on other sites

Well let me try to help you. ;D

 

Maybe you can use LIMIT 1 - this should give you last record.

Example:

select * from my_table limit 1

Or if you want to take specific records from 10-20 row you could use:

select * from my_table limit 10,10

 

As I understand, in your case it would be like this:

SELECT test.tag, test.waarde
FROM registratie
LEFT JOIN test ON registratie.registratieID = test.registratieID
LEFT JOIN oorsprong_gegevens ON registratie.oorsprong = oorsprong_gegevens.oorsprong
WHERE registratie.productieregister = '1'
AND test.tag='EF1' LIMIT 1;

 

Also you can try with MAX(registratieID) - if you use autonumber field it will give you the latest record.

 

I hope this will help you.

Well let me try to help you. ;D

 

Maybe you can use LIMIT 1 - this should give you last record.

Example:

select * from my_table limit 1

Or if you want to take specific records from 10-20 row you could use:

select * from my_table limit 10,10

 

As I understand, in your case it would be like this:

SELECT test.tag, test.waarde
FROM registratie
LEFT JOIN test ON registratie.registratieID = test.registratieID
LEFT JOIN oorsprong_gegevens ON registratie.oorsprong = oorsprong_gegevens.oorsprong
WHERE registratie.productieregister = '1'
AND test.tag='EF1' LIMIT 1;

 

Also you can try with MAX(registratieID) - if you use autonumber field it will give you the latest record.

 

I hope this will help you.

 

Lemme quick reply on this :P

I think u got it wrong with the limit thing.

 

LIMIT 1 gives u the first record he finds, not the last one of the list.

 

MAX() function indeed works, i already found this for myself.

 

Still thanks tough ^^

 

It really does depend on what your defining as your field to determine the "last" record.

SELECT MAX(auto_increment_column) WILL work however I don't recommend it because you're relying on auto increment working properly. If you don't have an auto_increment field you'll want to ORDER BY <defining column> LIMIT 0,1

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.