Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2014
    Posts
    1

    Unanswered: Subqueries in SQL

    Hi there,

    Just wanted to find out about creating subqueries in SQL.

    Is there a standard format?

    For example I have a query like so:

    SELECT
    drqueslist.queslist
    FROM
    drpartques
    INNER JOIN drqueslistgroup
    ON drqueslistgroup.kqueslistgroupid=drpartques.kquesl istgroupid
    INNER JOIN drqueslist
    ON drqueslist.kqueslistgroupid=drqueslistgroup.kquesl istgroupid
    WHERE
    drpartques.kpartid=1004265

    I want to wrap this inside of a SELECT statement and put an AS answer1 entry

    any clues or do I need more information?

  2. #2
    Join Date
    Jul 2015
    Posts
    7
    it will vary depending on use:

    Where clause:

    select *
    from table
    where table id in (
    SELECT
    drqueslist.queslist as entry
    FROM
    drpartques
    INNER JOIN drqueslistgroup
    ON drqueslistgroup.kqueslistgroupid=drpartques.kquesl istgroupid
    INNER JOIN drqueslist
    ON drqueslist.kqueslistgroupid=drqueslistgroup.kquesl istgroupid
    WHERE
    drpartques.kpartid=1004265
    )

    Select Clause:

    select (
    SELECT
    drqueslist.queslist as entry
    FROM
    drpartques
    INNER JOIN drqueslistgroup
    ON drqueslistgroup.kqueslistgroupid=drpartques.kquesl istgroupid
    INNER JOIN drqueslist
    ON drqueslist.kqueslistgroupid=drqueslistgroup.kquesl istgroupid
    WHERE
    drpartques.kpartid=1004265
    ) as answer1
    from table

    FROM clause:

    select answer1.entry
    from
    (
    SELECT
    drqueslist.queslist as entry
    FROM
    drpartques
    INNER JOIN drqueslistgroup
    ON drqueslistgroup.kqueslistgroupid=drpartques.kquesl istgroupid
    INNER JOIN drqueslist
    ON drqueslist.kqueslistgroupid=drqueslistgroup.kquesl istgroupid
    WHERE
    drpartques.kpartid=1004265
    ) as answer1

Posting Permissions

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