Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to Join with Top 1 Select?
Message
 
 
À
02/12/2004 19:25:45
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Versions des environnements
Visual FoxPro:
VFP 8 SP1
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
Visual FoxPro
Divers
Thread ID:
00966581
Message ID:
00966595
Vues:
8
This message has been marked as the solution to the initial question of the thread.
Hi Chris,

Try
OPEN DATABASE (HOME(2) + "Northwind\Northwind")
SELECT DIST ;
		Customers.customerid, Customers.contactname, ;
		Invoices.OrderID, Invoices.orderdate ;
	FROM Customers ;
		JOIN Invoices ON Customers.customerid = Invoices.customerid ;
	WHERE Invoices.customerid + DTOS(Invoices.orderdate) IN ( ;
			SELECT customerid + MAX(DTOS(orderdate))  FROM Invoices ;
				GROUP BY customerid)
>I'm creating a local view where I need only the top result from one of the tables in the view, but all the records in another. IE: All Customers, but only the most recent Invoice for each.
>
>SELECT cust.CustID, cust.LastName, cust.FirstName, Invoice.InvoiceID, Invoice.InvoiceNum, Invoice.Date FROM cust INNER JOIN invoice ON cust.CustID = invoice.cust ID (TOP 1 IN invoice????)
>
>Because it's a local view, I can't gracefully do it with a subquery, and I'd prefer to avoid SCANning through customer and inserting the results. A GROUP BY doesn't seem to work because I need the actual values from invoice, so I'm stuck.
--sb--
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform