Professional Web Applications Themes

Basic SELECT/FROM/WHERE/AND query - MySQL

I am running MySQL 4.0.1. I can run this query fine: SELECT * FROM form WHERE Email="com" This query doesn't work: SELECT * FROM form WHERE Email="com" AND Name="Name" It only tells me that there is an error in my syntax near Name="Name", and to check the manual for the proper syntax. I have tried && instead of AND. I have checked the official manual, but it had nothing new to offer. I even tried some of the examples for version 5, just in case....

  1. #1

    Default Basic SELECT/FROM/WHERE/AND query

    I am running MySQL 4.0.1. I can run this query fine: SELECT * FROM
    form WHERE Email="com"

    This query doesn't work: SELECT * FROM form WHERE
    Email="com" AND Name="Name"

    It only tells me that there is an error in my syntax near Name="Name",
    and to check the manual for the proper syntax. I have tried && instead
    of AND. I have checked the official manual, but it had nothing new to
    offer. I even tried some of the examples for version 5, just in case.

    Jerim79 Guest

  2. #2

    Default Re: Basic SELECT/FROM/WHERE/AND query

    On 3 Apr, 14:42, "Jerim79" <com> wrote: 

    I just copied and pasted that query into phpmyadmin and it ran
    perfectly version 5.1.16

    Captain Guest

  3. #3

    Default Re: Basic SELECT/FROM/WHERE/AND query

    On Apr 3, 9:06 am, "Captain Paralytic" <com> wrote: 


    >
    > I just copied and pasted that query into phpmyadmin and it ran
    > perfectly version 5.1.16[/ref]

    I appreciate your response, but that doesn't exactly fix my problem
    unless you are going to let me come over and use your computer. Any
    alternative ways to do this? I have tried AND and &&. I even tried
    using a comma.

    Jerim79 Guest

  4. #4

    Default Re: Basic SELECT/FROM/WHERE/AND query

    On 3 Apr, 15:50, "Jerim79" <com> wrote: 
    > [/ref]
    > [/ref]
    > [/ref]

    >
    > I appreciate your response, but that doesn't exactly fix my problem
    > unless you are going to let me come over and use your computer. Any
    > alternative ways to do this? I have tried AND and &&. I even tried
    > using a comma.[/ref]

    What I'm saying is that there isn't a syntax error per se.

    One good idea is to quote all non keywords with back ticks thus:
    SELECT * FROM `form` WHERE
    `Email`="com" AND `Name`="Name"

    Also, what do you get if you try:
    SELECT * FROM `form` WHERE
    `Name`="Name"

    or

    SELECT * FROM `form` WHERE
    `Name`="Name" AND `Email`="com"

    Captain Guest

  5. #5

    Default Re: Basic SELECT/FROM/WHERE/AND query

    On Apr 3, 10:59 am, Jerry Stuckle <net> wrote: [/ref]
    > [/ref]

    >
    > Perhaps that isn't your problem. Is this in an application? If so,
    > what's the entire code you're using - not just the SELECT statement?
    >
    > --
    > ==================
    > Remove the "x" from my email address
    > Jerry Stuckle
    > JDS Computer Training Corp.
    > net
    > ==================[/ref]

    SELECT * FROM `form` WHERE Email='$Email' AND Show='$Show'

    Now, before we go assuming it is a PHP issue, this statement works
    perfectly fine:
    SELECT * FROM `form` WHERE Email='$Email'

    Jerim79 Guest

  6. #6

    Default Re: Basic SELECT/FROM/WHERE/AND query

    On 3 Apr, 16:25, "Jerim79" <com> wrote: [/ref]
    > [/ref]
    > [/ref]


    >
    > SELECT * FROM `form` WHERE Email='$Email' AND Show='$Show'
    >
    > Now, before we go assuming it is a PHP issue, this statement works
    > perfectly fine:
    > SELECT * FROM `form` WHERE Email='$Email'
    >
    > - Show quoted text -[/ref]
    That tells us no more than the first post. Please answer the questions
    in my other post.


    Captain Guest

  7. #7

    Default Re: Basic SELECT/FROM/WHERE/AND query

    On 3 Apr 2007 08:25:40 -0700, Jerim79 wrote: 
    >> 
    >> 
    >>
    >> Perhaps that isn't your problem. Is this in an application? If so,
    >> what's the entire code you're using - not just the SELECT statement?[/ref]
    >
    > SELECT * FROM `form` WHERE Email='$Email' AND Show='$Show'
    >
    > Now, before we go assuming it is a PHP issue, this statement works
    > perfectly fine:
    > SELECT * FROM `form` WHERE Email='$Email'[/ref]

    Jerry asked for the surrounding code, not just the select. I semll a
    quoting issue. Build your select into a single string variable first so
    you can get the fully-expanded SQL out someplace where you can look at
    it. like

    $qry = "SELECT * FROM `form` WHERE Email='$Email' AND Show='$Show'";
    print "$qry\n";

    --
    When you have a thermic lance, everything looks like hours of fun.
    -- Christian Wagner in a.s.r
    Peter Guest

  8. #8

    Default Re: Basic SELECT/FROM/WHERE/AND query

    On Apr 3, 10:38 am, "Captain Paralytic" <com>
    wrote: 
    > [/ref]
    > [/ref]
    > [/ref]
    > [/ref]
    > [/ref]



    >
    > That tells us no more than the first post. Please answer the questions
    > in my other post.[/ref]

    I get the exact same results. The query works 100% with or without the
    ` marks, up until AND.

    Jerim79 Guest

  9. #9

    Default Re: Basic SELECT/FROM/WHERE/AND query

    Jerim79 wrote: 
    >> I just copied and pasted that query into phpmyadmin and it ran
    >> perfectly version 5.1.16[/ref]
    >
    > I appreciate your response, but that doesn't exactly fix my problem
    > unless you are going to let me come over and use your computer. Any
    > alternative ways to do this? I have tried AND and &&. I even tried
    > using a comma.
    >[/ref]

    Perhaps that isn't your problem. Is this in an application? If so,
    what's the entire code you're using - not just the SELECT statement?

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

  10. #10

    Default Re: Basic SELECT/FROM/WHERE/AND query

    Jerim79 wrote: 
    >> Perhaps that isn't your problem. Is this in an application? If so,
    >> what's the entire code you're using - not just the SELECT statement?
    >>
    >> --
    >> ==================
    >> Remove the "x" from my email address
    >> Jerry Stuckle
    >> JDS Computer Training Corp.
    >> net
    >> ==================[/ref]
    >
    > SELECT * FROM `form` WHERE Email='$Email' AND Show='$Show'
    >
    > Now, before we go assuming it is a PHP issue, this statement works
    > perfectly fine:
    > SELECT * FROM `form` WHERE Email='$Email'
    >[/ref]

    Ah, I just realized something. "Show" is a reserved word. You
    shouldn't be using it as a column name. But since you did, you need to
    surround it with back tickies - i.e. `Show`.

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

  11. #11

    Default Re: Basic SELECT/FROM/WHERE/AND query

    Jerim79 schrieb: 

    What's the value in $Show?

    Regards,
    Jo
    Joachim Guest

  12. #12

    Default Re: Basic SELECT/FROM/WHERE/AND query

    >SELECT * FROM `form` WHERE Email='$Email' AND Show='$Show'

    I smell a keyword: show. As in "show tables".

    SELECT * FROM `form` WHERE Email='$Email' AND `show`='$Show'
     

    You need to show the statement as it is passed to MySQL. The above
    search looks for an email address containing no and beginning with a
    dollar sign.


    Gordon Guest

  13. #13

    Default Re: Basic SELECT/FROM/WHERE/AND query


    "Jerim79" <com> wrote in message
    news:googlegroups.com... 


    Isn't NAME a reserved word?

    Perhaps:

    SELECT * FROM form WHERE Email="com" AND [Name]="Name"



    Sean Guest

Similar Threads

  1. Can this basic query be simplified?
    By Ciaran in forum MySQL
    Replies: 5
    Last Post: March 12th, 07:26 PM
  2. basic query question
    By Mike in forum MySQL
    Replies: 6
    Last Post: May 9th, 05:22 PM
  3. Query of Query to select a title first letter
    By Conti in forum Coldfusion Database Access
    Replies: 2
    Last Post: March 18th, 11:42 PM
  4. Basic query speed question
    By cobramichelle in forum Coldfusion Database Access
    Replies: 1
    Last Post: December 23rd, 05:48 PM
  5. Replies: 2
    Last Post: November 18th, 12:14 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