www.webdeveloper.com
Results 1 to 5 of 5

Thread: How do write a where clause with multiple numbers

Hybrid View

  1. #1
    Join Date
    May 2009
    Location
    Rochester, NY
    Posts
    372

    Question How do write a where clause with multiple numbers

    I'm spacing on this. I'm sure it's simple, but I can't recall it.

    I want to write a clause using a WHERE statement.

    SELECT * FROM products WHERE orders_id = 1 ORDER BY products_model

    This will work, but what if I want to get everything from where orders_id is 1, 2, 3, 4, 6, 10, 12, and 18? I want to report the values for all of those numbers. How would I go about doing that?

    Thanks!

  2. #2
    Join Date
    May 2009
    Location
    Rochester, NY
    Posts
    372
    I know I can do orders_id = 1 OR orders_id = 2, and so on, but is there a more standard way?

  3. #3
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,536
    Code:
    WHERE col_name IN(1,2,3,5,8,13)
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  4. #4
    Join Date
    May 2009
    Location
    Rochester, NY
    Posts
    372
    Aah, yes. Ok, thanks! I thought there was a more standard way.

  5. #5
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,536
    Just in case: it should probably be noted here that if those values come from another DB query, you could use a sub-query instead:
    Code:
    . . . WHERE col_name IN (SELECT id FROM some_table WHERE something=somethingelse)
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles