Question
Get Unique recordset with INNER JOINS
I am confused about how to fix this problem.
First my query:
<CFQUERY NAME="rndpick" DATASOURCE="absi">
SELECT DISTINCT catfit.prodid, modcats.catid, modcats.cat, prod.modlid, prod.prodtype, prodmat.prtnum, prodmat.brand, prodmat.modl, prodmat.features, prodmat.pic, prodmat.dcp, prodmat.prc, prodmat.shp
FROM ((catfit INNER JOIN prodmat ON catfit.prodid=prodmat.prodid) INNER JOIN ModCats ON Catfit.catid = ModCats.catid) INNER JOIN prod ON prod.modlid=catfit.modlid
WHERE ((Catfit.slsid)=1)
</cfquery>
Now I know that the DISTINCT would not work in this case becuase it looks at each records total value (all columns in query). I had to try. I have also tried to use the GROUP BY to no avail.
The Question: How can I use an SQL query (based on what I have above) to give my a unique recordset using the catfit.prodid column as the filter?
I have read that you can use two queries to pull this off but could not find a good example of it so I could make it work. The first qurey to get the distinct values for the column I need and the second query to get the rest of the vaules. Not sure how to do this in practice?
Your help is greatly appreciated!
First my query:
<CFQUERY NAME="rndpick" DATASOURCE="absi">
SELECT DISTINCT catfit.prodid, modcats.catid, modcats.cat, prod.modlid, prod.prodtype, prodmat.prtnum, prodmat.brand, prodmat.modl, prodmat.features, prodmat.pic, prodmat.dcp, prodmat.prc, prodmat.shp
FROM ((catfit INNER JOIN prodmat ON catfit.prodid=prodmat.prodid) INNER JOIN ModCats ON Catfit.catid = ModCats.catid) INNER JOIN prod ON prod.modlid=catfit.modlid
WHERE ((Catfit.slsid)=1)
</cfquery>
Now I know that the DISTINCT would not work in this case becuase it looks at each records total value (all columns in query). I had to try. I have also tried to use the GROUP BY to no avail.
The Question: How can I use an SQL query (based on what I have above) to give my a unique recordset using the catfit.prodid column as the filter?
I have read that you can use two queries to pull this off but could not find a good example of it so I could make it work. The first qurey to get the distinct values for the column I need and the second query to get the rest of the vaules. Not sure how to do this in practice?
Your help is greatly appreciated!
