0

Would like to figure out how to better retrieve data from database without performance cost.

Plan as follows:

  1. Select id from article table;
  2. store ids in List<int> arr;
  3. find out last article id. int x = arr.Count()
  4. Select * from article_tbl where id = x; Run query.
  5. Post it on you page.

Am I planning right? What is better way of retrieving data from database?

Thanks a lot

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
user610961
  • 181
  • 1
  • 10
  • are you just trying to select the latest article and what db are you using ? – Jon Black Mar 14 '11 at 16:13
  • Yes it can be solved like "Select top 1 from article_tbl order by date DESC". Thanks mate. But What is better way of retrieving data from database? I am working with SQLServer Express 2008 – user610961 Mar 14 '11 at 16:22

1 Answers1

0

Try something like this - you can call it "ad-hoc" or wrap it up in a stored procedure:

-- get the "latest" ID from the "Article" latest
-- but you need to define *latest* by WHAT criteria?? A date?? The ID itself??
DECLARE @LastID INT

SELECT TOP 1 @LastID = ID
FROM dbo.Article
ORDER BY ..........  -- order by date? id? what??

-- get the detail data for that ID from the "Article_tbl"
SELECT (list of columns)
FROM dbo.Article_tbl 
WHERE ID = @LastID
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459