How to check for unique value depending on another column value...

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Abhilash Etikala
    New Member
    • Jan 2010
    • 21

    How to check for unique value depending on another column value...

    I am having table which contains 2 columns (qid,round) and both columns can have repeated values but one constraint is for each 'round' the 'qid' values should not be repeated.

    example:
    round:1,1,1,2,2
    qid:1,2,3,1,2---should be unique for each round...

    can any body suggest me a query for this..??
  • rski
    Recognized Expert Contributor
    • Dec 2006
    • 700

    #2
    So you need unique constraint on both columns (qid,round)

    Comment

    • Abhilash Etikala
      New Member
      • Jan 2010
      • 21

      #3
      ya..depending on each other...

      Comment

      • rski
        Recognized Expert Contributor
        • Dec 2006
        • 700

        #4
        What do you mean? My english is not as good i'm afraid :).

        Comment

        • Abhilash Etikala
          New Member
          • Jan 2010
          • 21

          #5
          i mean the same as u said unique constraint on both columns...i think you understood what was my problem....

          Comment

          • rski
            Recognized Expert Contributor
            • Dec 2006
            • 700

            #6
            Yes I understood (i think i did) and that's why i suggested to create one uniqe constraint on both column because you want the pair of values (round,qid) to be unique don't you?

            Comment

            • Abhilash Etikala
              New Member
              • Jan 2010
              • 21

              #7
              ya exactly....so how to get it...and wat cud be the query...

              Comment

              • Abhilash Etikala
                New Member
                • Jan 2010
                • 21

                #8
                Hi rski, i got solution of course it was easy...just set a unique constraint on two columns by UNIQUE(column1, column2)...I think it is basic concept but i am very new to postgre sql....Thank you....

                Comment

                Working...