有这样的数据库
表1 country
    id cname
    1  中国 
    2  美国
     3  加拿大
表2 city
    id  name cid
    1    北京  1
    2    上海  1
    3    纽约  2
    4   旧金山 2
    5   温哥华  3select country.cname as cname ,city.name as cs from country,city where country.id=city.cid
显示的结果是:
中国 北京 
中国 上海 
美国 纽约 
美国 旧金山 
加拿大 温哥华 我现在想要的结果是:每个国家只显示一个城市
中国 北京 
美国 纽约 
加拿大 温哥华 

解决方案 »

  1.   

    select country.cname as cname ,city.name as cs from country,city where country.id=city.cid group by country.cname.
      

  2.   

    select a.*,c.cname from ttb2 a
    inner join (
    select cid,min(id) as mi from ttb2 group by cid) b
    on a.cid=b.cid and a.id=b.mi
    left join ttb1 c on a.cid=c.id
      

  3.   

    解决了哦 o(∩_∩)o... jf
      

  4.   

    Just simply use group by!