Ask a Question related to PERL Beginners, Design and Development.

  1. #1

    Default SQL annoyance

    Hi there, quick and annoying SQL problem, was debating about whether to post
    it here or DBI, I figured DBI was for DBI related issues, and this is just a
    plain SQL problem. Excuse me if I'm wrong though, but thought I'd ask
    anyway.
    I have an SQL statement as follows,
    SELECT * FROM memodata WHERE to=1 AND readdate=sent ORDER BY id ASC
    which fails giving an error on the to=1 part.
    I've tried doing that statement without the 'to=1 AND' part, and it works
    fine returning all and more of the data that I want. However when i ask it
    to be more specific, it fails. I've also tried
    SELECT * FROM memodata WHERE to=1
    which also fails on the to=1 part. I've also tried putting in other column
    names, like from=1, but that fails too. And I'm totally clueless as to why,
    as the syntax follows the manual on mysql.com exactly.
    Any pointers as to where I'm going wrong?
    Many thanks, and apologies once again if I should have posted this
    elsewhere. I'll know next time if I should ;)
    -Dan


    Dan Guest

  2. Similar Questions and Discussions

    1. MySQL Annoyance
      Hi all, I've finally had enough of this problem that I thought I'd see if there was a workaround. Every time I create a new view through the...
    2. Strange annoyance in Illustrator 10
      Although I convinced my work place to purchase alteast 3 licenses of illustrator CS I regret making that choice, it will be a long time again before...
    3. An annoyance in Save For Web
      In the Save For Web window, when you select a transparency matte color, there's no way to select an exact color without typing in the numbers...
    4. another annoyance
      FH MX windows. Working in one folder, change to another project and you have to change the save location and the export location and the open...
    5. Minor Annoyance in 4.0 LE
      Can someone tell me why this is happening all of a sudden?? I have PS 4.0 LE. When I go into explorer to open a jpg.....let's say it's called Lisa...
  3. #2

    Default Re: SQL annoyance

    Hi Dan,

    On Sun, 2004-01-04 at 03:34, dan wrote:
    > I have an SQL statement as follows,
    > SELECT * FROM memodata WHERE to=1 AND readdate=sent ORDER BY id ASC
    > which fails giving an error on the to=1 part.
    > I've tried doing that statement without the 'to=1 AND' part, and it works
    > fine returning all and more of the data that I want. However when i ask it
    > to be more specific, it fails. I've also tried
    > SELECT * FROM memodata WHERE to=1
    > which also fails on the to=1 part. I've also tried putting in other column
    > names, like from=1, but that fails too. And I'm totally clueless as to why,
    > as the syntax follows the manual on mysql.com exactly.
    > Any pointers as to where I'm going wrong?
    just wildly speculating, but I'd guess that "to" and "from" are typical
    string values (and not integers) - have you tried something like

    SELECT * FROM memodata WHERE to = '1'

    BTW: You can find out the column types by typing "describe memodata;" on
    your mysql command line.

    HTH,

    Philipp

    Philipp Traeder Guest

  4. #3

    Default Re: SQL annoyance

    Dan wrote:
    >
    > Hi there, quick and annoying SQL problem, was debating about whether to post
    > it here or DBI, I figured DBI was for DBI related issues, and this is just a
    > plain SQL problem. Excuse me if I'm wrong though, but thought I'd ask
    > anyway.
    >
    > I have an SQL statement as follows,
    >
    > SELECT * FROM memodata WHERE to=1 AND readdate=sent ORDER BY id ASC
    >
    > which fails giving an error on the to=1 part.
    >
    > I've tried doing that statement without the 'to=1 AND' part, and it works
    > fine returning all and more of the data that I want. However when i ask it
    > to be more specific, it fails. I've also tried
    >
    > SELECT * FROM memodata WHERE to=1
    >
    > which also fails on the to=1 part. I've also tried putting in other column
    > names, like from=1, but that fails too. And I'm totally clueless as to why,
    > as the syntax follows the manual on mysql.com exactly.
    >
    > Any pointers as to where I'm going wrong?
    It would be nice to know what error your getting, but the reason is certainly
    that both 'to' and 'from' are reserved words in MySQL. Take a look here

    [url]http://www.mysql.com/doc/en/Legal_names.html[/url]

    Quote your column names with backticks:

    SELECT * FROM memodata
    WHERE `to` = 1 AND `readdate` = `sent`
    ORDER BY `id` ASC

    and it should work for you.

    Cheers,

    Rob


    Rob Dixon Guest

  5. #4

    Default Re: SQL annoyance

    dan wrote:
    > Hi there, quick and annoying SQL problem, was debating about whether to post
    > it here or DBI, I figured DBI was for DBI related issues, and this is just a
    > plain SQL problem.
    So it should really be posted on an RDBMS list.
    > Excuse me if I'm wrong though, but thought I'd ask
    > anyway.
    > I have an SQL statement as follows,
    > SELECT * FROM memodata WHERE to=1 AND readdate=sent ORDER BY id ASC
    Please put spaces in your condition clauses, there is nothing magical about
    torturing the eyes.

    In addition to the concerns Rob raised about using reserved words [you can
    generalize this to say that generic names are just bad style anyway] I would
    suggest naming the fields you are taking. Some SQL engines cannot address
    fields that are not selectd by name. The select * construct is for dumps, not
    for analytical selects.

    select sender, receiver, time, date form mailhistory where receiver =
    $target_recipient;

    Joseph

    R. Joseph Newton Guest

Posting Permissions

  • You may not post new threads
  • You may 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