select distinct tab1.id from tab1,tab2 where tab1.age>20 or tab2.sex in 'man'

解决方案 »

  1.   

    如果 ID 在2个表中都是主键,应该建立连接:select tab1.id from tab1 join tab2 on tab1.id=tab2.id where tab1.age>20 or tab2.sex in 'man' 或select tab1.id from tab1, tab2 where tab1.id=tab2.id and (tab1.age>20 or tab2.sex in 'man')
      

  2.   

    select tab1.id from tab1 inner join tab2 on tab1.id=tab2.id 
    where tab1.age>20 or tab2.sex in 'man' 
      

  3.   

    select distinct tab1.id from tab1,tab2 where tab1.age>20 or tab2.sex in 'man' 
      

  4.   

    我也提供一种写法吧:
    select distinct id from ((select id from tab1 where age>20) union (select id from tab2 where sex in 'man')) as tab 
      

  5.   

    select distinct tab1.id from tab1,tab2 where tab1.id=tab2.id and (tab1.age>20 or tab2.sex in 'man')
      

  6.   

    Slect Distinct id From tab1 Where tab1.age > 20
    Union
    Select Distinct id From tab2 Where tab2.sex='man'
      

  7.   

    use distinct to try again!
      

  8.   

    distinct 你会用这个吗?如果会那么我就不明白你的意思了。