mysql - Sql: Setting distinct for one value of one column -
is possible set if seek created table 2 values match , 1 value specific value say, 1, won't allow you?
i want have table this:
table1_id: | table1_name: 1 | edgar 2 | rudy table2_id: | table2_table1_id |table2_active(bit): 1 | 1 | 1 (this okay) 2 | 1 | 0 (this okay) 3 | 1 | 1 (this not okay) // shouldn't work 4 | 1 | 0 (this still okay) 5 | 2 | 1 (this okay) 6 | 2 | 0 (this okay) 7 | 2 | 1 (this not okay) // shouldn't work 8 | 2 | 0 (this still okay)
i want able have many (x,0s) want able have 1 (x,1) how accomplished?
edit: possible solution:
create trigger active_check before insert on table2` if exists (select table2_id table_2 table2_table1_id = new.table2_table1_id active = 1) begin rollback transaction; homecoming end;
would utilize of new.table2_table1_id
work here though it's in own statement? if not how around that?
mysql sql unique distinct
No comments:
Post a Comment