Results 1 to 5 of 5
  1. #1
    Join Date
    Feb 2004
    Location
    Baltimore, MD
    Posts
    7

    Unanswered: SELECTing from a SELECT statement

    Is there a way to do this in straight SQL: Execute a SELECT query, then execute a SELECT query on the results of the first query?

    Thanks.

  2. #2
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    Assuming that your database engine supports derived tables, yes you can base one SELECT upon the results of another SELECT.

    -PatP

  3. #3
    Join Date
    Jul 2001
    Location
    Germany
    Posts
    189

    Wink

    Hello,

    what do you think about

    SELECT * FROM
    (SELECT * FROM query1 WHERE TAB=1)
    WHERE FIELD = 10;

    Hope that helps ?

    Best regards
    Manfred Peter
    Alligator Company Software GmbH
    http://www.alligatorsql.com

  4. #4
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    Don't you have to provide a table-alias for a derived table? I would expect you to need something like:
    Code:
    SELECT * FROM
       (SELECT * FROM query1 WHERE TAB=1) as A
       WHERE FIELD = 10;
    for that to work.

    -PatP

  5. #5
    Join Date
    Jul 2001
    Location
    Germany
    Posts
    189

    Cool Works without alias on many dbs

    Hello,

    this works also without an alias ... but when you want to join
    its better to use an alias like

    SELECT *
    FROM (SELECT * FROM table1) AS a,
    table2 b
    WHERE a.id = b.id

    Best regards
    Manfred Peter
    Alligator Company Software GmbH
    http://www.alligatorsql.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •