Let's say I need to be able to dynamically retrieve the last record in a table (ChData) in order to be able to continuously monitor the flow of data. Since theoretically there is no such thing defined in SQL, let's say I have an index column - ChTimestamp - (which, for some odd reason, is a DOUBLE), which grows monotonically. Thus, I want the row with the largest ChTimestamp value. The data columns would be Ch0, Ch1, and so on. Let's also assume that for some reason I am limited to using the LabVIEW database connectivity toolkit and because of that, I don't have full use of the SELECT statement but I have to supply the table and column names for the "SELECT FROM " and only the WHERE and the like predicates can be freely specified (I don't know how freely). What would be an elegant query to achieve the desired result? Thanks!
Kamenelegant query to achieve your result:select phonenumber
from dbms_vendors
where dbms in ('sql server','oracle','mysql','postgresql','sybase','db 2')
sorry, couldn't help it
:cool:|||select * from chdata
where
chtimestamp=(select max(chtimestamp) from chdata)
or am I missing something?
Alternatively you could write a trigger to update a known row in another version of the table with a single row so you can have a simpler where clause.
select * from mystupidtable where x='1'|||SELECT TOP 1 * FROM Table1 ORDER BY chTimestamp DESC|||Thank you very much, LoztInSpace and Peso. No it's not a homework, I'm a professional, it's just that I have to deal with so many different technologies, programming languages, APIs, etc., that sometimes it's just easier (not to mention quicker) to ask those who deal with it every day instead of trying to jump start my fried brain. :o
Kamen :angel:|||Maybe it is time to make your niche?|||Actually, small companies appreciate multivalent engineers like me. Plus, I'm too old to change. :cool:
Kamen
No comments:
Post a Comment