select * from A where sub table B.Rows.Count > 0

Posts   
 
    
alexdresko
User
Posts: 336
Joined: 08-Jun-2004
# Posted on: 27-Dec-2005 20:20:29   

Obviously that's not a real SQL query, but it illustrates what I want to do.

I want to get all rows from a table where each row's child collection contains at least one row.

Is that possible with LLBLGen?

Paul.Lewis
User
Posts: 147
Joined: 22-Aug-2005
# Posted on: 28-Dec-2005 05:22:08   

alexdresko wrote:

Obviously that's not a real SQL query, but it illustrates what I want to do.

I want to get all rows from a table where each row's child collection contains at least one row.

Is that possible with LLBLGen?

Wouldn't this query return all rows from A that contain rows in B?

SELECT A.* FROM A INNER JOIN B ON A.ID = B.FKID

alexdresko
User
Posts: 336
Joined: 08-Jun-2004
# Posted on: 28-Dec-2005 15:02:24   

Paul.Lewis wrote:

alexdresko wrote:

Obviously that's not a real SQL query, but it illustrates what I want to do.

I want to get all rows from a table where each row's child collection contains at least one row.

Is that possible with LLBLGen?

Wouldn't this query return all rows from A that contain rows in B?

SELECT A.* FROM A INNER JOIN B ON A.ID = B.FKID

Why yes it would! I think I'm just appplying my predicate expressions to the wrong object. I'll let you know if I can't figure it ou.

JimHugh
User
Posts: 191
Joined: 16-Nov-2005
# Posted on: 28-Dec-2005 22:49:08   

alexdresko wrote:

Paul.Lewis wrote:

alexdresko wrote:

Obviously that's not a real SQL query, but it illustrates what I want to do.

I want to get all rows from a table where each row's child collection contains at least one row.

Is that possible with LLBLGen?

Wouldn't this query return all rows from A that contain rows in B?

SELECT A.* FROM A INNER JOIN B ON A.ID = B.FKID

Why yes it would! I think I'm just appplying my predicate expressions to the wrong object. I'll let you know if I can't figure it ou.

Actually, it would repeat row A for each joined row in B even though it doesn't show any columns from B.

In order to get single instances of A.* rows, you need to use the DISTINCT keyword or the IN clause

SELECT DISTINCT A.* FROM A INNER JOIN B ON A.ID = B.FKID

Here is real world example


use Northwind

select A.* from Customers A
inner join Orders B on A.CustomerID = B.CustomerID
-- Returns 830 rows

select distinct A.* from Customers A
inner join Orders B on A.CustomerID = B.CustomerID
-- Returns 89 rows

select A.* from Customers A
where A.CustomerID in (select CustomerID from Orders)
-- Returns 89 rows

Paul.Lewis
User
Posts: 147
Joined: 22-Aug-2005
# Posted on: 29-Dec-2005 04:31:59   

Thank you Jim. I sit corrected if not correctly.

tprohas
User
Posts: 257
Joined: 23-Mar-2004
# Posted on: 15-May-2006 20:59:49   

I think I'm trying to do the same thing as alexdresko and have not been able to accomplish this. I have another thead started about this. In my problem I thought I had it solved, but the LLBLGen query inserts the distinct keyword which is causing the query to return the wrong results. I want to duplicate entities return in my situation.

Here is my thread, can anyone help? http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=6171

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 16-May-2006 07:56:32   

Here is my thread, can anyone help?

We will be following up your thread. Thanks