1

I can't figure this out. How would I be able to create a table in MySQL where I can organize it by two unique columns but one of the columns is only unique based on the other column For example

Rep | ID

A --|-- 1

A --|-- 2

A --|-- 3

B --|-- 1

B --|-- 2

C --|-- 1

C --|-- 2

C --|-- 3

C --|-- 4

And so on...

To explain what I'm doing: My table will hold images. These images will all correlate to their report. But there will be many images in every report. These images need to be uniquely identified 1-9 (If there was 9 images in that report).

So as shown in my example: the ID has to auto_increment and has to be unique; based upon the report it's associated with.

Thanks for any help.

************Found the answer here*********** mysql two column primary key with auto-increment

Community
  • 1
  • 1
Syntax--
  • 11
  • 2

1 Answers1

0

Try this:

You can create UNIQUE INDEX on both column.

ALTER TABLE `tablea` ADD UNIQUE INDEX `UniqueIndexName` (`Rep`, `Id`)
Saharsh Shah
  • 28,687
  • 8
  • 48
  • 83
  • I tried something like that at first then it failed and I guess I had tunneled vision.. Thank you so much Saharsh, you just saved my night. xD – Syntax-- Dec 20 '13 at 09:18
  • Actually.. I forgot to mention.. id needs to auto increment. – Syntax-- Dec 20 '13 at 09:27