create table B (
b_id char(12) not null,
b_flag int default 0 not null,
constraint pB primary key
clustered (b_id)
)
create table A (
a_id char(18) not null,
b_id char(12) not null,
a_title varchar(255) not null,
constraint pA primary key
clustered (a_id),
constraint fA foreign key (b_id)
references B (b_id)
)
위와 같이 테이블이 구성되어 있고 테이블에 데이터가
table B
b_id b_flag
('000000000001', 1)
('000000000002', 1)
('000000000003', 0)
('000000000004', 0)
table A
a_id b_id
a_title
('000000000000000001', '000000000001', 'title1')
('000000000000000002', '000000000001', 'title1')
('000000000000000003', '000000000002', 'title2')
('000000000000000004', '000000000002', 'title2')
('000000000000000005', '000000000003', 'title3')
('000000000000000006', '000000000004', 'title4')
('000000000000000007', '000000000004', 'title5')
이렇게 있다고 할 때
뽑아내고자 하는 결과값은
a_id a_title
('000000000000000001', 'title1')
('000000000000000003', 'title2')
('000000000000000005', 'title3')
('000000000000000006', 'title4')
('000000000000000007', 'title5')
이렇습니다.
MySQL 에서는
select a.a_id, a.a_title from A a, B b where a.b_id = b.b_id and
b.b_flag = 0
union
select a.a_id, a.a_title from A a, B b where a.b_id = b.b_id and
b.b_flag = 1 group by b.b_id
order by a.a_id;
이렇게 하면 원하는 결과값을 뽑을 수 있는데, Sybase에서는
그렇지가 않네요...
방법 좀 가르쳐 주세요...
|