Thread: select using !=

    #1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Posts
    3
    Rep Power
    0
    I'm using this sql statement to retrieve records from my table where the field view does not equal 1 (view is an INT field size 4)

    $sql = mysql_query("select * from mytable where view !=1 order by date_written desc");

    But it doesn't work - it returns no records.

    I changed it to this and this works:

    $sql = mysql_query("select * from mytable where view ='' OR ISNULL(view) order by date_written desc");

    But I thought the first one would work - can anyone put me right as to why the first select query doesn't work?

    TIA, Tony
  2. #2
  3. Banned (not really)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 1999
    Location
    Brussels, Belgium
    Posts
    14,648
    Rep Power
    4493
    I tried your first statement and it worked fine for me. i'm not sure what the problem could be. what version are you using??

    ---John Holmes...
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Posts
    1
    Rep Power
    0
    In mysql, the proper "not equal to" statement is <> not !=
  6. #4
  7. No Profile Picture
    Apprentice Deity
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 1999
    Location
    Niagara Falls (On the wrong side of the gorge)
    Posts
    3,237
    Rep Power
    19
    Actually, either != or <> are perfectly acceptable.

Similar Threads

  1. select in a select box by typing??
    By ihugo in forum HTML Programming
    Replies: 1
    Last Post: October 21st, 2003, 11:57 AM
  2. select across multiple tables (UNION)
    By vickistanfield in forum MySQL Help
    Replies: 3
    Last Post: September 26th, 2003, 09:05 PM
  3. SELECT something FROM (SELECT something2 FROM ...) ...
    By loudo in forum Firebird SQL Development
    Replies: 3
    Last Post: August 21st, 2003, 05:27 AM
  4. Dynamic value of select box based on other select box
    By etherwolf in forum HTML Programming
    Replies: 6
    Last Post: October 16th, 2001, 11:11 AM
  5. select box changes other select box...
    By etherwolf in forum PHP Development
    Replies: 6
    Last Post: October 11th, 2001, 12:29 PM

IMN logo majestic logo threadwatch logo seochat tools logo