Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Select the max record on 2nd table
Message
From
01/03/2005 07:04:50
 
 
To
01/03/2005 03:51:46
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00991467
Message ID:
00991496
Views:
15
>I have 2 tables. the 1st table called ITEM - keep detail about the goods to sales, 2nd called transaction keep sales transaction information for the item.
>
>How can using SQL syntax to list out every item with last transaction date and price?
>
>
>Thanks.
CREATE CURSOR Item (idSales I,idItem i,txtRow C(20))
FOR K=1 TO 10
INSERT INTO ITEM VALUES (m.k,RAND()*10,[sales]+STR(m.k))
NEXT
CREATE CURSOR Transaction (idTransaction I,idItem I,dDate D,yPrice Y)
FOR K=1 TO 100
	iItem=INT(RAND()*10)
	IF LOOKUP(Item.idSales,m.iItem,Item.idItem)>0
		INSERT INTO Transaction VALUES (m.k,m.iItem,DATE()+RAND()*5,RAND()*1000)
	ENDIF
NEXT

IF VERSION(5)>800
	SELECT * FROM Item I LEFT JOIN ;
		(SELECT * FROM Transaction T WHERE DTOS(dDate)+BINTOC(idTransaction)=(SELECT MAX(DTOS(dDate)+BINTOC(idTransaction)) FROM Transaction WHERE idItem=T.idItem)) T;
		ON T.idItem=I.idItem
ELSE	
	SELECT * FROM Item I LEFT JOIN Transaction T ON T.idItem=I.idItem;
		WHERE DTOS(dDate)+BINTOC(idTransaction)=(SELECT MAX(DTOS(dDate)+BINTOC(idTransaction)) FROM Transaction WHERE idItem=T.idItem)
ENDIF
Previous
Reply
Map
View

Click here to load this message in the networking platform