Professional Web Applications Themes

mySQL query writing problem - MySQL

I have a table with a dozen or so fields. I am trying to return all 12 fields in all records that contain an entry in the field named 'week'. This select does that: "SELECT * FROM foo WHERE NOT ISNULL(week) ORDER BY week DESC"; but it also includes all other records that do not have an entry in the week field after the DESC ones have been listed. How can I modify the query to only return the ones that have an entry in week and none of the other ones? I thought NOT ISNULL would take care of ...

  1. #1

    Default mySQL query writing problem

    I have a table with a dozen or so fields. I am trying to return all 12
    fields in all records that contain an entry in the field named 'week'.
    This select does that:

    "SELECT * FROM foo WHERE NOT ISNULL(week) ORDER BY week DESC";

    but it also includes all other records that do not have an entry in the
    week field after the DESC ones have been listed. How can I modify the
    query to only return the ones that have an entry in week and none of the
    other ones? I thought NOT ISNULL would take care of it but it doesn't.
    JackM Guest

  2. #2

    Default Re: mySQL query writing problem

    JackM wrote:
    > I have a table with a dozen or so fields. I am trying to return all 12
    > fields in all records that contain an entry in the field named 'week'.
    > This select does that:
    >
    > "SELECT * FROM foo WHERE NOT ISNULL(week) ORDER BY week DESC";
    >
    > but it also includes all other records that do not have an entry in the
    > week field after the DESC ones have been listed. How can I modify the
    > query to only return the ones that have an entry in week and none of the
    > other ones? I thought NOT ISNULL would take care of it but it doesn't.
    The fields probably do contain information - like an empty string. But
    not knowing how week is defined, it's hard to say what might be in there.

    Remember - an empty string is a value, whereas NULL is specifically the
    lack of a value.

    If this is a varchar field, you can check with something like:

    "SELECT * FROM foo WHERE NOT ISNULL(week) AND week<>'' ORDER BY week DESC.

    Or you can correct your database to replace the empty strings with nulls.

    --
    ==================
    Remove the "x" from my email address
    Jerry Stuckle
    JDS Computer Training Corp.
    [email]jstucklexattglobal.net[/email]
    ==================
    Jerry Stuckle Guest

  3. #3

    Default Re: mySQL query writing problem

    Jerry Stuckle wrote:
    > JackM wrote:
    >
    >> I have a table with a dozen or so fields. I am trying to return all 12
    >> fields in all records that contain an entry in the field named 'week'.
    >> This select does that:
    >>
    >> "SELECT * FROM foo WHERE NOT ISNULL(week) ORDER BY week DESC";
    >>
    >> but it also includes all other records that do not have an entry in
    >> the week field after the DESC ones have been listed. How can I modify
    >> the query to only return the ones that have an entry in week and none
    >> of the other ones? I thought NOT ISNULL would take care of it but it
    >> doesn't.
    >
    >
    > The fields probably do contain information - like an empty string. But
    > not knowing how week is defined, it's hard to say what might be in there.
    >
    > Remember - an empty string is a value, whereas NULL is specifically the
    > lack of a value.
    >
    > If this is a varchar field, you can check with something like:
    >
    > "SELECT * FROM foo WHERE NOT ISNULL(week) AND week<>'' ORDER BY week DESC.
    >
    > Or you can correct your database to replace the empty strings with nulls.
    >
    Thanks Jerry. The field is varchar and hd been defaulted to NULL so your
    suggestion worked perfectly.

    But in the interest of furthering my query structure education, does
    that select you wrote translate to something approximating "AND week is
    less than or greater than empty"? Just trying to understand how the <>
    works in the statement.
    JackM Guest

Similar Threads

  1. mysql++ i mysqlpp::Query problem
    By jaccurek@op.pl in forum MySQL
    Replies: 1
    Last Post: July 26th, 10:02 AM
  2. Query problem moving from mysql 4 to 5
    By Justin Koivisto in forum MySQL
    Replies: 2
    Last Post: February 21st, 03:09 PM
  3. MySQL Query Problem
    By cf101 in forum Coldfusion Database Access
    Replies: 7
    Last Post: June 10th, 07:45 PM
  4. Problem with MySQL Query
    By Phillip Blancher in forum PHP Development
    Replies: 13
    Last Post: January 14th, 09:14 AM
  5. PHP/MySQL Query Problem in Dreamweaver
    By Aeris Leonna in forum PHP Development
    Replies: 2
    Last Post: October 20th, 03:22 PM

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
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139