2013-01-08 127 views
-1

选择栏这是另一种表列value.what不对的查询选择这是另一个表列值

select 
    geoName 
from 
    hgeo h 
where 
    geoName not in (select (select column_name 
          from information_schema.columns 
          where ((column_name = h.levelName) and (table_Name = 'flatgeo'))) 
        from flatgeo) 

我认为有一些问题

(select 
    (select column_name 
     from information_schema.columns 
     where ((column_name = h.levelName) and (table_Name = 'flatgeo'))) 

怎么写专栏?

+3

更容易阅读,比较容易回答。 –

+0

你想做什么? – Bridge

回答

1

您不能使用元信息来更改查询的形状。除非你想下去动态SQL路径(这可以迅速得到复杂的),我会去以下:

SELECT 
    geoName 
FROM hgeo h 
WHERE 
    NOT EXISTS (SELECT * FROM flatgeo f 
     WHERE 
     (h.levelName = 'value1' and f.value1 = h.geoName) OR 
     (h.levelName = 'value2' and f.value2 = h.geoName) 
     //Repeat for each possible levelName value. 
    ) 
0

您应该在列geoname之前使用tablename。像hgeo.geoname。 你想知道hgeogeoname是不是在flatgeo

1

你可以试试这个

select GeoName from HGeo where HGeo.GeoName not in 
(select FlatGeo.value1 from FlatGeo union 
select FlatGeo.value2 from FlatGeo union 
select FlatGeo.value3 from FlatGeo) 
相关问题