Results 1 to 6 of 6

Thread: Query Question

  1. #1
    Join Date
    Feb 2004
    Posts
    8

    Angry Unanswered: Query Question

    How would I do a query like this:

    Get users that have 'a' and 'b' and 'c' and 'd' or 'x' or 'y'....ect.

    Everything I try times out

    Thanks,
    Trey

  2. #2
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    You're gonna have to help us a little...

    Post the table DDL, sample data like..

    INSERT INTO TABLE(Col list)
    SELECT values UNION ALL
    SELECT values UNION ALL
    SELECT values UNION ALL
    SELECT values
    GO

    And what the result set should be...

    Do that, and you'll have an answer in minutes....
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

  3. #3
    Join Date
    Feb 2004
    Posts
    8
    Here is a small example of what I have....it is created on the fly from a vb.net program....i know there is a much better way of doing this then what I have.....I'm just not sure how.

    SELECT DISTINCT c.*
    FROM dbo.def c
    WHERE (id IN
    (SELECT def.id
    FROM def INNER JOIN
    transaction ON def.id = transaction.id
    WHERE (transaction.reason_id = '4790') AND (transaction.type_id = '4706') AND
    (transaction.created_date > '1/1/1990 12:00:00') AND (transaction.created_date < '3/16/2004 12:00:00') AND
    (transaction.removed_verified_date IS NULL))) OR
    (id IN
    (SELECT def.id
    FROM def INNER JOIN
    transaction ON def.id = transaction.id
    WHERE (transaction.reason_id = '4753') AND (transaction.type_id = '4706') AND
    (transaction.created_date > '1/1/1990 12:00:00') AND (transaction.created_date < '3/16/2004 12:00:00') AND
    (transaction.removed_verified_date IS NULL))) OR
    (id IN
    (SELECT def.id
    FROM def INNER JOIN
    transaction ON def.id = transaction.id
    WHERE (transaction.reason_id = '4767') AND (transaction.type_id = '4706') AND
    (transaction.created_date > '1/1/1990 12:00:00') AND (transaction.created_date < '3/16/2004 12:00:00') AND
    (transaction.removed_verified_date IS NULL))) OR
    (id IN
    (SELECT def.id
    FROM def INNER JOIN
    transaction ON def.id = transaction.id
    WHERE (transaction.reason_id = '4777') AND (transaction.type_id = '4707') AND
    (transaction.created_date > '1/1/1990 12:00:00') AND (transaction.created_date < '3/16/2004 12:00:00') AND
    (transaction.removed_verified_date IS NULL))) AND (id IN
    (SELECT def.id
    FROM def INNER JOIN
    transaction ON def.id = transaction.id
    WHERE (transaction.reason_id = '4769') AND (transaction.type_id = '4707') AND
    (transaction.created_date > '1/1/1990 12:00:00') AND (transaction.created_date < '3/16/2004 12:00:00') AND
    (transaction.removed_verified_date IS NULL))) AND (id IN
    (SELECT def.id
    FROM def INNER JOIN
    transaction ON def.id = transaction.id
    WHERE (transaction.reason_id = '4767') AND (transaction.type_id = '4707') AND
    (transaction.created_date > '1/1/1990 12:00:00') AND (transaction.created_date < '3/16/2004 12:00:00') AND
    (transaction.removed_verified_date IS NULL))) AND (id IN
    (SELECT def.id
    FROM def INNER JOIN
    transaction ON def.id = transaction.id
    WHERE (transaction.reason_id = '4773') AND (transaction.type_id = '4707') AND
    (transaction.created_date > '1/1/1990 12:00:00') AND (transaction.created_date < '3/16/2004 12:00:00') AND
    (transaction.removed_verified_date IS NULL)))

  4. #4
    Join Date
    Feb 2004
    Posts
    8
    Is that all the help u need....or do i need to include more info.....i'm totally lost with the problem.

    Thanks,
    Trey

  5. #5
    Join Date
    Oct 2002
    Posts
    66

    Re: Query Question

    Originally posted by TreyElliott
    How would I do a query like this:

    Get users that have 'a' and 'b' and 'c' and 'd' or 'x' or 'y'....ect.

    Everything I try times out

    Thanks,
    Trey
    Select * from MyTable
    where users between 'a' and 'd'
    or users in ('x', 'y')

  6. #6
    Join Date
    Feb 2004
    Posts
    8
    sorry....that was just a simple example.....the longer one is acutally what i am tring to do....thanks

    Trey

Posting Permissions

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