Professional Web Applications Themes

How use this query better ??? - Microsoft SQL / MS SQL Server

Hello, Someone knows the way of simplify this query: Table_1 Field1A-Field1B-Field1C ABC-123-90 ABC-567-90 ABC-890-90 DEF-147-90 DEF-258-90 Select *from Table_2 where Field2A like 'ABC' and Field2B like '123' And Field2A like 'ABC' and Field2B like '567' And Field2A like 'ABC' and Field2B like '890' And Field2A like 'DEF' and Field2B like '147' And Field2A like 'DEF' and Field2B like '258' And Field2C = '90' I wouldnt like to have hardcoding this query, so, there is a way to do it better thinking that Table_1 maybe increase ??? is better use a joins here ??? how ??? Any help is greatly appreciated....

  1. #1

    Default How use this query better ???

    Hello,

    Someone knows the way of simplify this query:

    Table_1
    Field1A-Field1B-Field1C
    ABC-123-90
    ABC-567-90
    ABC-890-90
    DEF-147-90
    DEF-258-90

    Select *from Table_2
    where
    Field2A like 'ABC' and Field2B like '123'
    And
    Field2A like 'ABC' and Field2B like '567'
    And
    Field2A like 'ABC' and Field2B like '890'
    And
    Field2A like 'DEF' and Field2B like '147'
    And
    Field2A like 'DEF' and Field2B like '258'
    And
    Field2C = '90'

    I wouldnt like to have hardcoding this query,
    so, there is a way to do it better thinking
    that Table_1 maybe increase ???

    is better use a joins here ??? how ???

    Any help is greatly appreciated.


    lubiel Guest

  2. #2

    Default Re: How use this query better ???

    try...

    select *
    from tb2 join tb1 on tb2.col1=tb1.col1 and tb2.col2=tb1.col2 and
    tb2.col3=tb1.col3
    where tb2.col1 in ('ABC','DEF')
    and tb2.col2 in ('123','567','890','147','258')
    and tb2.col3='90'

    --
    -oj
    RAC v2.2 & QALite!
    http://www.rac4sql.net


    "lubiel" <com> wrote in message
    news:035d01c3507c$3010ccc0$gbl... 


    oj Guest

  3. #3

    Default Re: How use this query better ???

    Hi

    It is not clear if your fields are one long formatted field or three
    separate fields! When posting please post the DDL (create table statement
    etc.), example data using insert statements and expected output and
    expected output.

    The query you posted will never return anything as
    Field2A like 'ABC' and Field2B like '123'
    And
    Field2A like 'ABC' and Field2B like '567'

    are mutually exclusive.

    You may get a better result from

    Select *from Table_2
    where ( ( Field2A = 'ABC'
    AND Field2B IN ( '123' , '567' , '890' ) )
    OR ( Field2A = 'DEF'
    AND Field2B IN ( '147' , '258' ) ) )
    AND Field2C = '90'


    John
     


    "lubiel" <com> wrote in message
    news:035d01c3507c$3010ccc0$gbl... 


    John Guest

Similar Threads

  1. Creating data query from mySQL stored query!?
    By johnegbert in forum Coldfusion Database Access
    Replies: 2
    Last Post: August 5th, 09:28 PM
  2. Query of Queries with constructed query using QueryNew()and QueryAddRow()
    By LeadFoot in forum Coldfusion - Advanced Techniques
    Replies: 2
    Last Post: August 4th, 02:00 PM
  3. Query of Queries on query New type query
    By david_h in forum Coldfusion Database Access
    Replies: 2
    Last Post: May 6th, 08:55 PM
  4. CAML Query: Multiple Query Fields Issue
    By Jon F. in forum ASP.NET Web Services
    Replies: 0
    Last Post: May 12th, 08:19 PM
  5. Replies: 1
    Last Post: July 2nd, 09:09 AM

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