表只有一个,tab1
_______________________________________________id name re text
______________________________________________1 aa dfdf 1112 cc aa 2222
_______________________________________________第一步,取得 text=111的name(取得值为aa)
第二步,取得 re=aa(第一步查出来的结果)的name(取得值为cc)能否将这两个查询写成一条语句,取得aa和cc,
请大家帮忙
_______________________________________________id name re text
______________________________________________1 aa dfdf 1112 cc aa 2222
_______________________________________________第一步,取得 text=111的name(取得值为aa)
第二步,取得 re=aa(第一步查出来的结果)的name(取得值为cc)能否将这两个查询写成一条语句,取得aa和cc,
请大家帮忙
name
from
tab1
where
re in(
select
name
from
tab1
where
`text`='111'
)
--或者
select
a.name
from
tab1 a,
tab2 b
where
a.re=b.name
and
b.`text`='111'
name
from
tab1
where
re in(
select
name
from
tab1
where
`text`='111'
)
--或者
select
a.name
from
tab1 a,
tab2 b
where
a.re=b.name
and
b.`text`='111'
from tab1 a inner join tab1 b on a.name=b.re
where a.text='111'
http://dev.mysql.com/doc/refman/5.1/zh/sql-syntax.html#join
13.2.7.1. JOIN语法