SQL query select from table and group on other column...

Posted by scaryjones on Stack Overflow See other posts from Stack Overflow or by scaryjones
Published on 2011-02-19T12:20:09Z Indexed on 2011/02/19 15:25 UTC
Read the original article Hit count: 155

Filed under:
|

I'm phrasing the question title poorly as I'm not sure what to call what I'm trying to do but it really should be simple.

I've a link / join table with two ID columns. I want to run a check before saving new rows to the table.

The user can save attributes through a webpage but I need to check that the same combination doesn't exist before saving it. With one record it's easy as obviously you just check if that attributeId is already in the table, if it is don't allow them to save it again.

However, if the user chooses a combination of that attribute and another one then they should be allowed to save it.

Here's an image of what I mean:

enter image description here

So if a user now tried to save an attribute with ID of 1 it will stop them, but I need it to also stop them if they tried ID's of 1, 10 so long as both 1 and 10 had the same productAttributeId.

I'm confusing this in my explanation but I'm hoping the image will clarify what I need to do.

This should be simple so I presume I'm missing something.

© Stack Overflow or respective owner

Related posts about sql

Related posts about grouping