Results 1 to 5 of 5
  1. #1
    Join Date
    Sep 2003
    Posts
    9

    Unanswered: When to use Select 'X'

    Hi,

    Please write me when and why we use following statement

    Select 'X' from table_name
    where condition

    'X' is not the field of the table.

    Thanks

    GS

  2. #2
    Join Date
    Aug 2003
    Location
    Where the Surf Meets the Turf @Del Mar, CA
    Posts
    7,776
    Provided Answers: 1

    Re: When to use Select 'X'

    Originally posted by Guddusp
    Hi,

    Please write me when and why we use following statement

    Select 'X' from table_name
    where condition

    'X' is not the field of the table.

    Thanks

    GS
    Almost exclusively I use it in subqueries.
    My rule of thumb is that no table should exist in the FROM clause
    when it does not contribute any column to the selected items.

    SELECT STUDENT_NAME
    FROM STUDENT_TABLE ST
    WHERE EXISTS
    (SELECT 'X'
    FROM COURSE_TABLE CT
    WHERE ST.COURSE_ID = 'CSC101'
    );

    HTH & YMMV

  3. #3
    Join Date
    Sep 2003
    Posts
    9

    Need more clarifications

    Thanks for your reply.

    You are right, I want to use it in subquery. However I need following clarifications

    1. You mean to say that there is no COURSE_TABLE in database.

    2. In the where clause of subquery, you used STUDENT_Table. Why?

    3. In which scenario, I could use "Select 'X' ".

    GS

  4. #4
    Join Date
    Oct 2003
    Posts
    22

    Re: When to use Select 'X'

    Its not possible to read a table but not return 0 rows and 0 columns 0f data.
    In that case this query is used.

  5. #5
    Join Date
    Oct 2003
    Posts
    22

    Re: When to use Select 'X'

    You cannt select from a table without return any results.
    If u want to do so, use the above query.
    Last edited by stephen_pe; 10-24-03 at 09:44.

Posting Permissions

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