+ Reply to Thread
Results 1 to 5 of 5

SQL Query to get count of matching data from two table

  1. #1
    Registered User
    Join Date
    09-21-2012
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    61

    SQL Query to get count of matching data from two table

    Hi all,

    I have 3 tables :

    Travellers_Report-

    Name Country Place_of_visit Return_date
    A United States Los Angeles 2/27/2013
    B United Arab Emirates DUBAI 2/21/2013
    C Puerto Rico San Juan 2/28/2013
    D United States Los Angeles 2/27/2013
    E United States Boston 2/27/2013
    F Malaysia Kulalampur 3/1/2013
    G United Arab Emirates DUBAI 2/15/2013
    H Malaysia Kulalampur 3/15/2013
    I United States Los Angeles 2/27/2013

    Company_presence-

    Country City
    United States Los Angeles
    United Arab Emirates DUBAI
    United States Boston

    I need to compare the 'Travellers_Report' table's 'Place_of_visit' field to 'Company_presence' table's 'City field' and get the count.
    Expected output:

    Country Place_of_visit Count
    United States Los Angeles 3
    United Arab Emirates DUBAI 2
    United States Boston 1

    as of now i have 2 queries but dont know how to connect this to get the expected result.
    Please Login or Register  to view this content.
    and
    Please Login or Register  to view this content.
    Please suggest some solutions...

  2. #2
    Registered User
    Join Date
    09-21-2012
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    61

    Re: SQL Query to get count of matching data from two table

    Played around with this and got:

    Please Login or Register  to view this content.
    Now only Two columns is there 'Facility' & 'CityCount'. How to add one more column in beginning (Country) by altering this query?

  3. #3
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2505 Win 11
    Posts
    24,748

    Re: SQL Query to get count of matching data from two table

    Please Login or Register  to view this content.
    Try the above
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  4. #4
    Registered User
    Join Date
    09-21-2012
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    61

    Re: SQL Query to get count of matching data from two table

    Hi,

    I posted same question by mistake again. How to delete that post?

    Also above query is working fine. One more thing. This query will compare the two tables and get the result where place of visit in 1st table and City in 2nd table matches i.e. Travellers_Report.Visit = Company_Presence.City
    How to get the count of not matching records? tried
    Please Login or Register  to view this content.
    in the same query but not getting the correct result. Pls suggest some solutions.

  5. #5
    Registered User
    Join Date
    09-21-2012
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    61

    Re: SQL Query to get count of matching data from two table

    Finally got it....

    Please Login or Register  to view this content.
    Last edited by Kiran2012; 03-18-2013 at 02:28 AM. Reason: typo

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1