SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Wizard
    Join Date
    Jan 2005
    Location
    blahblahblah
    Posts
    1,447
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    comma separated string / delete IN ()

    Hi,

    I'm sure there's a way to delete multiple rows of a table by using a comma separated string, and IN().

    I just can't find the syntax...

    DELETE FROM table WHERE names IN(name1,name2,name3);

    What would be the correct syntax? Would IN() work with string values and numerical values as well?

    Regards,

    -jj.

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,347
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    yes, it works with both numeric and character data

    it also works with columns, which is how this is interpreted --

    ... WHERE names IN ( name1 , name2 , name3 )

    if name1, name2, and name3 are not columns, then they are probably meant to have been strings, in which case you gots to put quotes around dem

    ... WHERE names IN ( 'name1' , 'name2' , 'name3' )

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Wizard
    Join Date
    Jan 2005
    Location
    blahblahblah
    Posts
    1,447
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks rudy


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
  •