views:

541

answers:

5

In this post "select with nested select" I read that SQL Compact 3.5 (SP1) support nested SELECT clause. But my request not work:

t1 - table 1 t2 - table 2 c1, c2 = columns

select 
 t1.c1, 
 t1.c2, 
 (select count(t2.c1) from t2 where t2.id = t1.id) as count_t 
from 
 t1

Does SQL Compact 3.5 SP1 support nested SELECT clause in this case?

Update:

SQL Compact 3.5 SP1 work with this type of nested request:

  • SELECT ... from ... where .. IN (SELECT ...)
  • SELECT ... from (SELECT ...)
A: 

Do you need a FROM clause in your nested select?

Clyde
Yes. I need it.
Sasha
A: 

Maybe you need

select * from LogMagazines where id = (select max id from UserRoles)

?

Nate Bross
Same problem: "There was an error parsing the query. [ Token line number = 1,Token line offset = 40,Token in error = select ]"
Sasha
Maybe the post you cited is wrong, and only 3.5SP1 supports the sub-select queries?
Nate Bross
I use the 3.5 SP1.
Sasha
+1  A: 

Try running select max(Id) from UserRoles And make sure this returns a proper result. Then try select * from LogMagazines where id = With that result, its possible you have an error somewhere.

MindStalker
BTW, id = (select ...)Is invalid if the subselect returns multiple lines, then you'd want id IN (select ....) though I'm not sure if that is valid with Compact 3.5
MindStalker
Thank you. Select * ... IN () work with SQL Compact 3.5 (SP1). But in my case i need another nested request.I update my question to point new problem.
Sasha
+2  A: 

You're attempting to equate a scalar value with what is notionally a result set.

Try

select * from LogMagazines where id IN (select max(id) from UserRoles)

Ok, I answered the question and you asked a completely new and different question which is not quite how its supposed to work, but to answer the new question what you need to do is a join:

SELECT 
    t1.c1,  
    t1.c2,  
    count_t.c
FROM 
    t1 JOIN (select id, count(t2.c1) as c from t2 GROUP BY t2.id) count_t 
       ON t1.id = count_t.id

Or thereabouts

Murph
Thank you. Request work fine. I update my question to point new problem...
Sasha
Ok, I've updated my answer!
Murph
A: 

Thank all for help and advise.

The final answer for question - NO. SQL Compact 3.5 SP1 does not support nested select clause.

Sasha