database-query

What's the most efficient way to select the last n rows in a table without changing the table's structure?

What's the most efficient way to select the last n number of rows in a table using mySQL? The table contains millions of rows, and at any given time I don't know how large the table is (it is constantly growing). The table does have a column that is automatically incremented and used as a unique identifier for each row. ...

Getting records from between Date X and Date Y from my Access database?

I have a table called Recharge in a Access Database. Some of the fields are RechargeDate, Account, Number, etc. I wanted to retrieve all records between two dates so I wrote the following query: string Query = "select * from Recharge where Account='" + comboBox1.Text + "' and RechargeDate between '"+dateTimePicker1.Value.Date.ToShort...

How to select top n rows from a datatable/dataview in asp.net

How to select top n rows from a datatable/dataview in asp.net.currently I am using the following code by passing the table and number of rows to get the records but is there a better way. public DataTable SelectTopDataRow(DataTable dt, int count) { DataTable dtn = dt.Clone(); for (int i = 0; i < count; i++) { ...

Select distinct values from many tables from a SQL Server query using group by and order by?

Hi I'm trying to select distinct top 10 url, it's count(url) and size from log_table joining other tables too. I tried the following SQL Server query: select distinct top 10 url, count(url) as hits, size as data from log_table where log_table.IP in (select IPAddress from IP where IP.IPId in ...