My goal is to get a query written. I have three tables, A, B and C. The tables are written such that A.bID = B.bID, and B.cID = C.cID. This basically allows me to write a query where I link a record from a to b, and link the b record to a record from c. So far so good, simple query.
What my problem is... one of the columns included in the query (let's call it C.col3) has to have unique values; the values in this column can only show up once in the query result, but other columns from the other tables do not have this requirement.
Can anybody help me write this query?
Thanks...
Update 1:
Here is the table layout (sorry, I have to use generic names)
Table A
aID, bID, aCol1, aCol2, aCol3 ... aCol10
Table B
bID, cID, bCol1, bCol2, bCol3 ... bCol10
Table C
cID, cCol1, cCol2, col3, cCol4 ... cCol10
Without the unique value constraint in col3, I would write the query like this:
SELECT
A.aID, A.bID, A.aCol1 ... A.aCol10,
B.bID, B.cID, B.bCol1 ... B.bCol10,
C.cID, C.cCol1, C.cCol2, C.col3 ... C.cCol10
FROM
A, B, C
WHERE
A.bID = B.bID AND B.cID = C.cID
... but of course that doesn't make sure the that values in C.col3 are unique.
Update 2:
More info...
Table A and Table B have a one to many relationship; A is the "header", B is the "item".
Table B and Table C have a one to one relationship.
These tables are part of a caching mechanism, so lots of data that looks similar, but is still different in some cols.
Since A is the header, most of the duplicate values will be found in A.
I first need to order the rows by A.aID, but then after that I only need the first rows returned, where the value for C.col3 does not appear in a previous row for that col.
Does that make things a little clearer, or am I still not making any sense? :)
Final Update:
I chose Bartosz Klimek's answer as it was the closest to what I needed; I just had to modify the nested join clause in the middle.
Thank you all for your help!