SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Wizard silver trophy TheOriginalH's Avatar
    Join Date
    Aug 2000
    Location
    Thailand
    Posts
    4,810
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Making sense of a query....

    PHP Code:
    'SELECT a.id, a.filename, a.name, a.description
            FROM media a 
            WHERE 1 = 1
            #-AND-# #-ORDERBY-# #-GROUPBY-#'

    The above query (there is a string replace function for the dodgy bit at the end) has me a little confused.

    Why the "WHERE 1=1" bit? Will that not always evaluate to true?

    And why the media.a?
    ~The Artist Latterly Known as Crazy Hamster~
    922ee590a26bd62eb9b33cf2877a00df
    Currently delving into Django, GIT & CentOS

  2. #2
    SitePoint Guru SSJ's Avatar
    Join Date
    Jan 2007
    Posts
    830
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There is no meaning to use 1=1 here as It will always evauated to True.

    Why Media a?
    Here is a is called an Alias for Table Media and you can refer the table Media via a.

  3. #3
    reads the ********* Crier silver trophybronze trophy longneck's Avatar
    Join Date
    Feb 2004
    Location
    Tampa, FL (US)
    Posts
    9,854
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    actually, the 1=1 is very important. it lets you blindly add more conditions to there where clause without having to worry about whether it is the first condition (and therefore shouldn't be preceded by an AND).


Bookmarks

Posting Permissions

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