Results 1 to 4 of 4

Thread: Sql query to retrieve all rows with a unique column value

  1. #1
    Join Date
    Mar 2016
    Posts
    3

    Sql query to retrieve all rows with a unique column value

    Here is a sample of my expected result:

    medical_thor_ref_num transaction_id rendering_provider_key
    7390 1020658961_1_2_00081324100017 13450583002761700000000000463400000000
    7290 1020658961_1_2_00081324100011 13450583002761700000000000463400000000
    7240 1020658961_1_2_00081324100010 13450583002761700000000000463400000000
    7340 1020658961_1_2_00081324100014 13450583002761700000000000463400000000
    7490 1020658961_1_2_00081342040001 13450583002761700000000000463400000000
    7040 1020658961_1_2_00081324100001 13450583002761700000000000463400000000
    7640 1020658961_1_2_00081342040008 13450583002761700000000000463400000000
    7540 1020658961_1_2_00081342040002 13450583002761700000000000463400000000
    7440 1020658961_1_2_00081324100027 13450583002761700000000000463400000000
    7190 1020658961_1_2_00081324100008 13450583002761700000000000463400000000
    7140 1020658961_1_2_00081324100007 13450583002761700000000000463400000000
    7090 1020658961_1_2_00081324100002 13450583002761700000000000463400000000
    7590 1020658961_1_2_00081342040007 13450583002761700000000000463400000000


    I need to retrieve all rows with the same rendering_provider_key. Your help is highly appreciated. Thanks

  2. #2
    Join Date
    Nov 2002
    Location
    New Jersey, USA
    Posts
    3,932
    Is it for one key? You can use

    SELECT *
    FROM table
    WHERE rendering_provider_key=134505830027617000000000004 63400000000

  3. #3
    Join Date
    Mar 2016
    Posts
    3
    Quote Originally Posted by skhanal View Post
    Is it for one key? You can use

    SELECT *
    FROM table
    WHERE rendering_provider_key=134505830027617000000000004 63400000000
    Thanks Skhanal but its not for just 1 key. That was just a sample of my expected results. I need all records grouped by the same rendering provider key.

  4. #4
    Join Date
    Nov 2002
    Location
    New Jersey, USA
    Posts
    3,932
    You can use

    SELECT <col1>, <col2>...
    FROM table
    GROUP BY rendering_provider_key

    But you must use some grouping function like COUNT, MAX, MIN, SUM, AVG on all columns listed in SELECT list unless that column is part of GROUP BY list.

    I am not exactly sure what your result set should look like, but even ORDER BY may work for you

    SELECT *
    FROM table
    ORDER BY rendering_provider_key

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
  •