Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect SQL query (oracle) for subquery #298

Open
baxster opened this issue Feb 9, 2014 · 0 comments
Open

Incorrect SQL query (oracle) for subquery #298

baxster opened this issue Feb 9, 2014 · 0 comments

Comments

@baxster
Copy link

baxster commented Feb 9, 2014

I tried this query:

        var states =
            from fts in DataContext.GetTable<FirmToState>()
            orderby fts.StateChangeDate descending
            select fts;

        var query =
            from f in DataContext.GetTable<Firm>()
            select new
            {
                FirmID = (long?)f.ID,
                StateID = states.Where(s => s.FirmID == f.ID)
                                .Select(s => (long?)s.StateID)
                                .FirstOrDefault(),
            };

Classes of metadata:

    public class FirmToState
    {
        public DateTime StateChangeDate { get; set; }
        public long FirmID { get; set; }
        public long StateID { get; set; }
    }

    public class Firm
    {
        public long ID { get; set; }
    }

query formatted in oracle as:

SELECT 
f.ID, 
( 
    SELECT tn11.* 
-- should be: SELECT tn11.STATE_ID
    FROM 
    ( 
        SELECT tn1.*, ROWNUM as rnn1 
        FROM 
        ( 
            SELECT 
                s.STATE_ID 
            FROM 
                VFIRM_TO_STATES s 
            WHERE 
                s.FIRM_ID = f.ID 
            ORDER BY 
                s.STATE_CHANGE_DATE DESC 
        ) tn1 
    ) tn11 
    WHERE 
        tn11.rnn1 <= 1 
) as c1 
FROM 
VFIRMS f 

Oracle reports error ORA-00913: too many values
When "SELECT tn11.*" is replaced with "SELECT tn11.STATE_ID" , the query executes without errors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant