我必须进入表中检索参数,然后返回到同一个表中,根据参数检索数据。
<cfquery name = "selnm" datasource = "Moxart">
select SelName from AuxXref
where Fieldname = <cfqueryparam value = "#orig#">
</cfquery>
<cfset selname = selnm.SelName>
<cfquery name = "fld" datasource = "Moxart">
select Fieldname, DBname from AuxXref
where SelName = <cfqueryparam value = "#selname#">
</cfquery>
这可以在一个查询中完成吗?
答案 0 :(得分:4)
这样的事情可能会满足您的要求。
select fieldname, DBname
from AuxXref
where selname in
(select distinct selname
from auxXref
where fieldname = <cfqueryparam value = "#orig#">
)
and fieldname <> <cfqueryparam value = "#orig#">
如果子查询返回多行,而您只想要一行,那么您必须指定所需的那一行。
答案 1 :(得分:2)
您可以在一个查询中执行此操作:
<cfquery name = "fld" datasource = "Moxart">
select Fieldname, DBname, SelName from AuxXref
where SelName = <cfqueryparam value = "#orig#">
AND FieldName = <cfqueryparam value = "#orig#">
</cfquery>