sql server ce query question

srdva59

Active member
Joined
Feb 21, 2009
Messages
28
Programming Experience
Beginner
hi,
i have two tables
products that have the name and code and stock_products that have the
current stock

and i want in a single query see the especific value of the table stock_products
for example

from table one: code of product and from table two the stock of the
product

in secund table i have many records that belong for the same product
but i want only the last record

now the great question
how can i do that?
thanks a lot for your help :)

i using sql server ce
 
Can you show us what the other table colums are please?
 
hi,

the colums of the stock_products are:

stock
codartigo
date

and the colums of the products are:

id
codartigo
date

thanks a lot for your help :)
 
try

VB.NET:
SELECT
	a.codartigo,
	(
		SELECT TOP 1 stock
		FROM stock_products
		WHERE codartigo = a.codartigo
		ORDER BY [date] DESC
	) AS stock
FROM products AS a
ORDER BY a.codartigo

let me know if that works.
 
Back
Top