Execute subqueries using clauses, selected items, and attribute test values.
SELECT a.id FROM (SELECT b.id FROM AllType b) AS a WHERE a.id = 1Use this Objective-C code:
SUPQuery *query1 = [SUPQuery getInstance]; [query1 select:@"b.id"]; [query1 from:@"AllType":@"b"]; SUPQuery *query2 = [SUPQuery getInstance]; [query2 select:@"a.id"]; [query2 fromQuery:query1:@"a"]; SUPAttributeTest *ts = [SUPAttributeTest getInstance]; ts.attribute = @"a.id"; [ts setTestValue:@"1"]; [query2 where:ts]; SUPQueryResultSet *qs = [SUP101DB executeQuery:query2];
SELECT (SELECT count(1) FROM AllType c WHERE c.id >= d.id) AS cn, id FROM AllType dUse this Objective-C code:
SUPQuery *selQuery = [SUPQuery getInstance];
[selQuery select:@"count(1)"];
[selQuery from:@"AllType":@"c"];
SUPAttributeTest *ttt = [SUPAttributeTest getInstance];
ttt.attribute = @"c.id";
ttt.operator = SUPAttributeTest_GREATER_EQUAL;
SUPColumn *cl = [SUPColumn getInstance];
cl.alias = @"d";
cl.attribute = @"id";
ttt.testValue = cl;
[selQuery where:ttt];
SUPObjectList *selectItems = [SUPObjectList getInstance];
SUPSelectItem *item = [SUPSelectItem getInstance];
item.query = selQuery;
item.asAlias = @"cn";
[selectItems add:item];
SUPQuery *subQuery2 = [SUPQuery getInstance];
subQuery2.selectItems = selectItems;
[subQuery2 from:@"AllType" :@"d"];
SUPQueryResultSet *qs = [SUP101DB executeQuery:subQuery2];