Results 1 to 6 of 6
  1. #1
    3 Star Lounger
    Join Date
    Jul 2001
    Posts
    283
    Thanks
    0
    Thanked 0 Times in 0 Posts

    select statement (Access 2002)

    I would like to know in this statement

    select * from products where 1=1 ....

    What does the phrase 1=1 mean?

    Thanks

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: select statement (Access 2002)

    Since 1=1 is always true (at least, that's what my math teachers told me), this is the same as

    SELECT * FROM PRODUCTS WHERE True

    or even

    SELECT * FROM PRODUCTS

  3. #3
    Bronze Lounger
    Join Date
    Nov 2001
    Location
    Arlington, Virginia, USA
    Posts
    1,394
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Re: select statement (Access 2002)

    <P ID="nt"><font size=-1>(No Text)</font>
    Attached Images Attached Images

  4. #4
    3 Star Lounger
    Join Date
    Jul 2001
    Posts
    283
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: select statement (Access 2002)

    if that is the case, then what is the point of saying:

    select * from product where 1=1 and productid = '12' and supplierid="30" and ........

    Thanks

  5. #5
    Silver Lounger GARYPSWANSON's Avatar
    Join Date
    Aug 2001
    Location
    Frederick, Maryland, USA
    Posts
    1,788
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Re: select statement (Access 2002)

    ... there is no point in saying 1=1 as this evaluated to true and is essentially ignored by the query and returns the complete dataset. The and productid = '12'... will drive the query.

    Of course, we programmers tend to do a lot of "ODD" things to remind us of something. Perhaps 1 = 1 is to remind the person to check the first record, or to put in a condition to check the first record = 1 or eat lunch at 1 or something else <img src=/S/sarcasm.gif border=0 alt=sarcasm width=15 height=15> - sorry, couldn't resist that.
    Regards,

    Gary
    (It's been a while!)

  6. #6
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: select statement (Access 2002)

    It may be there to provide a stub for the rest of the WHERE clause. If code takes the SQL string and adds conditions based on input from a user, for example, having the WHERE 1=1 expression already in the SQL means that the code merely has to add " AND Somecondition = SomeValue" and doesn't have to worry about whether there is already a WHERE clause or whether the whole thing, including the word "WHERE" and any connecting operators like AND or OR.

    In other words, someone may have gotten lazy. <img src=/S/grin.gif border=0 alt=grin width=15 height=15>
    Charlotte

Posting Permissions

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