Professional Web Applications Themes

Query to find names in 2 tables - Microsoft SQL / MS SQL Server

Is there a possibility to find names in 2 tables with one query? The tables are not related. Table1: CustomerNr int(4) Name Varchar(70) Table2: CustomerNr int(4) Name Varchar(70) table1: 33 Danny 47 John 59 Mary table2: 137 Peter 12 Mary 57 Chris I am trying to create a query that get's 1 record if I query for 'Danny', and 2 records if I query for 'Mary' Thank you in advance, Danny Springer...

  1. #1

    Default Query to find names in 2 tables

    Is there a possibility to find names in 2 tables with one query? The
    tables are not related.
    Table1:
    CustomerNr int(4)
    Name Varchar(70)

    Table2:
    CustomerNr int(4)
    Name Varchar(70)



    table1: 33 Danny
    47 John
    59 Mary

    table2: 137 Peter
    12 Mary
    57 Chris

    I am trying to create a query that get's 1 record if I query for
    'Danny', and 2 records if I query for 'Mary'

    Thank you in advance,
    Danny Springer

    Danny Guest

  2. #2

    Default Re: Query to find names in 2 tables

    SELECT *
    FROM
    (SELECT customernr, [name]
    FROM Table1
    UNION ALL
    SELECT customernr, [name]
    FROM Table2) X
    WHERE [name] = 'Mary'

    --
    David Portas
    ------------
    Please reply only to the newsgroup
    --



    David Guest

  3. #3

    Default Re: Query to find names in 2 tables

    David Portas wrote:
     

    Life can be so simple.............

    Thank you for your fast answer.
    Danny

    Danny Guest

Similar Threads

  1. Accessing duplicate field names from different tables
    By cakesy in forum Coldfusion Database Access
    Replies: 7
    Last Post: March 10th, 09:45 AM
  2. CFQUERYPARAM with tables names
    By Don Vaillancourt in forum Coldfusion Database Access
    Replies: 5
    Last Post: October 6th, 09:00 PM
  3. Convert a query to a list, or find an item in a query
    By Laverda668 in forum Macromedia ColdFusion
    Replies: 2
    Last Post: April 7th, 07:41 PM
  4. How to rename Access tables and field names?
    By Marshal in forum ASP Database
    Replies: 3
    Last Post: October 9th, 05:46 PM

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