peddel Posted February 4, 2009 Share Posted February 4, 2009 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'; Quote Link to comment https://forums.phpfreaks.com/topic/143742-solved-selecting-last-element/ Share on other sites More sharing options...
anthylon Posted February 5, 2009 Share Posted February 5, 2009 Well let me try to help you. 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. Quote Link to comment https://forums.phpfreaks.com/topic/143742-solved-selecting-last-element/#findComment-755091 Share on other sites More sharing options...
peddel Posted February 5, 2009 Author Share Posted February 5, 2009 Well let me try to help you. 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 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 ^^ Quote Link to comment https://forums.phpfreaks.com/topic/143742-solved-selecting-last-element/#findComment-755097 Share on other sites More sharing options...
anthylon Posted February 5, 2009 Share Posted February 5, 2009 LOL Independent what is last for you. I am kidding - my bad. But I am glad you got solution . LOL Quote Link to comment https://forums.phpfreaks.com/topic/143742-solved-selecting-last-element/#findComment-755099 Share on other sites More sharing options...
killah Posted February 5, 2009 Share Posted February 5, 2009 If you going to use limit 1 and only want the last row. You can always add ORDER BY `registratieID` DESC LIMIT 1 Quote Link to comment https://forums.phpfreaks.com/topic/143742-solved-selecting-last-element/#findComment-755102 Share on other sites More sharing options...
anthylon Posted February 5, 2009 Share Posted February 5, 2009 I think MAX(field) is better was in this case. Sorting will probably take more time to execute. Quote Link to comment https://forums.phpfreaks.com/topic/143742-solved-selecting-last-element/#findComment-755108 Share on other sites More sharing options...
peddel Posted February 5, 2009 Author Share Posted February 5, 2009 If you going to use limit 1 and only want the last row. You can always add ORDER BY `registratieID` DESC LIMIT 1 This is indeed a posibility also Quote Link to comment https://forums.phpfreaks.com/topic/143742-solved-selecting-last-element/#findComment-755118 Share on other sites More sharing options...
aschk Posted February 5, 2009 Share Posted February 5, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/143742-solved-selecting-last-element/#findComment-755122 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.