MySQL 'IN' Operator Syntax

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Obi Wan Shinobi

    MySQL 'IN' Operator Syntax

    Hello,

    I'm learning about MySQL but i'm having problems with the 'IN'
    operator. For example:

    SELECT * FROM TABLE_NAME WHERE ID = IN ('9','19','3',' 10');

    ....gives me a syntax error. I've also tried it with (9,19,3,10) but it
    gives me the same problem.

    I have a feeling i'm missing something very simple.

    Any pointers would be greatly appreciated.

    Many Thanks.
  • Chris Hope

    #2
    Re: MySQL 'IN' Operator Syntax

    Obi Wan Shinobi wrote:
    [color=blue]
    > I'm learning about MySQL but i'm having problems with the 'IN'
    > operator. For example:
    >
    > SELECT * FROM TABLE_NAME WHERE ID = IN ('9','19','3',' 10');
    >
    > ...gives me a syntax error. I've also tried it with (9,19,3,10) but it
    > gives me the same problem.[/color]

    Get rid of the = so it reads like:

    SELECT * FROM TABLE_NAME WHERE ID IN (9,19,3,10);

    Chris

    --
    Chris Hope
    The Electric Toolbox Ltd

    Comment

    • Chris Hope

      #3
      Re: MySQL 'IN' Operator Syntax

      Obi Wan Shinobi wrote:
      [color=blue]
      > I'm learning about MySQL but i'm having problems with the 'IN'
      > operator. For example:
      >
      > SELECT * FROM TABLE_NAME WHERE ID = IN ('9','19','3',' 10');
      >
      > ...gives me a syntax error. I've also tried it with (9,19,3,10) but it
      > gives me the same problem.[/color]

      Get rid of the = so it reads like:

      SELECT * FROM TABLE_NAME WHERE ID IN (9,19,3,10);

      Chris

      --
      Chris Hope
      The Electric Toolbox Ltd

      Comment

      • Chris Hope

        #4
        Re: MySQL 'IN' Operator Syntax

        Obi Wan Shinobi wrote:
        [color=blue]
        > I'm learning about MySQL but i'm having problems with the 'IN'
        > operator. For example:
        >
        > SELECT * FROM TABLE_NAME WHERE ID = IN ('9','19','3',' 10');
        >
        > ...gives me a syntax error. I've also tried it with (9,19,3,10) but it
        > gives me the same problem.[/color]

        Get rid of the = so it reads like:

        SELECT * FROM TABLE_NAME WHERE ID IN (9,19,3,10);

        Chris

        --
        Chris Hope
        The Electric Toolbox Ltd

        Comment

        • Bill Karwin

          #5
          Re: MySQL 'IN' Operator Syntax

          Obi Wan Shinobi wrote:
          [color=blue]
          > SELECT * FROM TABLE_NAME WHERE ID = IN ('9','19','3',' 10');[/color]

          Don't use = with IN. For example:
          SELECT * FROM TABLE_NAME WHERE ID IN ('9','19','3',' 10');

          See http://dev.mysql.com/doc/mysql/en/Co...Operators.html, this
          lists all the syntax for comparison operations.

          Regards,
          Bill K.

          Comment

          Working...