Q:

sql - Installing unequal data into a table where another attribute is the same

I want insert username for some company, but username should not be repeat in one company. 
id | company_name|                  id|username|company |
---|-------------|                  --|--------|--------|
1  |   company1  |                  1 | admin  |company1| !!
2  |   company2  | 1 ------------ M 2 | admin  |company1| !!
3  |   company3  |                  3 | admin  |company2|      

A:

You want a unique index in the second table:  table2(username, company).
If you attempt to insert a duplicate user name within a company, then you will get an error.

