Subject Re: sql puzzle
Author Svein Erling
Happy new year to you too, James!

Is the statement you are looking for simply

SELECT item.itemname, invoicedetails.price
FROM item
JOIN invoicedetails on invoicedetails.itemid = item.itemid
JOIN invoice i1 on i1.invno = invoicedetails.invno
WHERE NOT EXISTS (SELECT * FROM invoice i2 WHERE
i2.invno > i1.invno)

As an alternative, you could try

SELECT item.itemname, invoicedetails.price
FROM item
JOIN invoicedetails on invoicedetails.itemid = item.itemid
WHERE NOT EXISTS (SELECT * FROM invoice WHERE
invoice.invno > invoicedetails.invno)

I do not know which of these two statements perform better than the
other.

Set

> Happy new year everyone. :-)
>
> Can somebody help me with this. I want to form a sql statement that
> could get the price of each item from the lastest invoice. Here are
> some of the table definition. the ITEM table has (itemid, itemname),
> INVOICE table has (invno, invdate), INVOICEDETAILS table(invno,
> itemid, price). This definition table is not the complete one I just
> list the important one. I am having a problem contructing it, I am
> trying to avoid using Stored Procedures or Views as much as
> possible.