I have 4 columns in a table:
id (primary)
vendor (which is a foreign key for vendor table)
vendorno (which is actually a product number from that vendor)
product (which is a foreing key for product table)*
*I'm separating the vendorno from the product table
so product table is general in definition so two different vendor
carrying the same product would point to one product id.
I don't know if this was a smart move but oh well...
I want to pull, for a given vendor, all duplicate vendornos
which cannot happen either with same or different product id
because vendorno should be a unique number from that vendor.
I'm currently struggling with this:
SELECT DISTINCT vendor, vendorno, COUNT(vendorno) AS NumOcc
FROM vendor_map
GROUP BY vendor, vendorno
HAVING (count(vendorno)>1);
any insight??
BONUS TIP: if you also know how to call from the vendor table to
substitute in the final query result the actual name of the vendor
instead of the id that'll be super!!