Parent - Child SELECT query

FreeriderUK

Well-known member
Joined
Jun 27, 2006
Messages
100
Location
London
Programming Experience
10+
I have 3 tables: tbCategory, tbCustomers & tbInvoices.

I want to show in a DataGridView, a list of the invoices in a particular category, including the Customer Name.

VB.NET:
InvoiceNumber   CustomerName   CategoryDescription
--------------------------------------------------
123456789012    Mr Jones       Cleaning
123456789013    Mr Smith       Cleaning
.
.
123456789099    Mrs Green      Cleaning


The related tables are:

tbCategory:
CategoryID
CategoryDescription

tbCustomers:
CustomerID
CustCategoryID
CustomerName

tbInvoices:
InvoiceID
InvCustomerID
InvoiceNumber

Put simply, I want to list all invoices related to all the customers in the selected Category

What is the SELECT statement I should use to fill the DataSet?
 
thanks for telling us what DB youre using. Here is the oracle code for this:

VB.NET:
SELECT 
  *
FROM
  tbCategory
  INNER JOIN
  tbCustomers
  ON(CategoryID = CustCategoryID)

  INNER JOIN
  tbInvoices
  ON(InvCustomerID = CustomerID)

WHERE
  CategoryID = :pCategoryID

If youre not on Oracle, some minor syntax adjustment will be needed
 

Latest posts

Back
Top