select b.* from( select uid as id from a union all select fid from a) t join b on t.id=b.id a.uidºÍa.fid¶ÔÓ¦ÔÚb.idÖеÄ×ֶΣ¬ ¾Í±ÈÈç˵uidÊÇÖ¸Óû§µÄid,fidÊÇÖ¸Óû§µÄÅóÓÑid ÎÒÏë²é³öÀ´Óû§µÄÐÕÃûºÍÓû§ÅóÓѵÄÐÕÃû£¬ÕâÑù²î¿Ï¶¨ÊDz»ÐÐµÄ °Ñ±íµÄ½á¹¹£¬²âÊÔÊý¾Ý ¼°ÄãÒªµÄ½á¹û ¸æËßÎÒÃÇ°¡ a ±í id uid fid 1 1 2 2 3 5 b id name 1 uid1 2 uid2 3 uid3 4 uid4 5 uid5 ÎÒÏëÒªµÃµ½ a.id = 1 ¶ÔÓ¦µÄuidµÄnameºÍfid¶ÔÓ¦µÄname id uname fname 1 uid1 uid2 2 uid3 uid5 SQL code:
create table ta (id int,uid int,fid int) insert into ta select 1, 1, 2 u