Please help me solve Query Problem.

capedech

Well-known member
Joined
Oct 29, 2008
Messages
62
Programming Experience
Beginner
Please help me solve Query Problem.

I want to see the last record from a table.
Right now I did it like this :
SELECT NoResep FROM TResep
ORDER BY NoResep DESC
LIMIT 0, 1

It works, but if there's more than 2000 records in that table and more than 2 tables, the program will work slower than usual.

Is there other query that I can use but faster and have the same result ?
 
What does "last record" mean?
I can guess, but I want to make sure. You should be aware that the answer is probably going to be "your database is badly designed and needs to be changed"
 
Please help me solve Query Problem.

I want to see the last record from a table.
Right now I did it like this :
SELECT NoResep FROM TResep
ORDER BY NoResep DESC
LIMIT 0, 1

It works, but if there's more than 2000 records in that table and more than 2 tables, the program will work slower than usual.

Is there other query that I can use but faster and have the same result ?

If you are attempting to find the "Last" entry of a table given the specific ordered column you might try this:
VB.NET:
SELECT TOP(1) NoResep FROM TResep
ORDER BY NoResep DESC

But that is determinate upon the NoResep field being uniquely constrained. If it is not, and say there are multiple rows with the same value of the NoResep field, you will either need to narrow your Order By clause to include an addition column for more specific ordering or else you'll only grab the first row of the table and that might not be the exact "last" entry you were seeking. As well, the syntax I've provided is T-SQL, so is specific to Microsoft Database products, as Oracle and MySQL use a different notation.
 
IF you have an auto number as the id.. then

select * FROM myTable
where ID = MAX(ID)

would give u the last ID
 

Latest posts

Back
Top