Select Random Records with Group By?

Hi,
I currently select random records by using this type of SQL:
(SELECT *
FROM ( SELECT *
FROM ( SELECT *
FROM TABLEA
ORDER BY dbms_random.value
WHERE ROWNUM <= 100
Based on the following data, I now want to still pick out random records but I only want 1 record from the same ID and START_DATE but where the FLAG could be Y or N.
So with grouping by ID and START_DATE, I need to still be able to choose the record if it has anything from 1 entry or 10 entries per ID and START_DATE.
Could this be performed with a GROUP BY?
ID START_DATE FLAG
1 12/12/2005 Y
1 12/12/2005 N
1 12/12/2005 N
1 30/12/2005 Y
1 30/12/2005 N
1 30/12/2005 N
2 10/10/2005 Y
2 07/07/2005 Y
Thanks for any help.
Daniel

Try this [not tested]:
SELECT *
     FROM
          (SELECT *
               FROM
               ( SELECT
                          ID
                         ,START_DATE
                         ,FLAG
                         ,ROW_NUMBER() OVER
                              (PARTITION BY ID,START_DATE ORDER BY dbms_random.value) RN
                    FROM TABLEA
               ORDER BY dbms_random.value
     WHERE RN = 1
          AND ROWNUM <= 100
     ;

Similar Messages

  • Selecting random records out of a table

    Hi,
    I guess this question isn't new, but I didn't found anything about this using the search of this forum.
    How can I get e.g. 5 random records out of a table?
    I have a small table, which stores the special offers of a shop. Let us say, there are 30 records in it. How can I fetch (e.g.) 5 random records of this table?
    I tried to use this statement in a loop:
    SELECT t_item_id FROM tbl_special_offers SAMPLE (1) WHERE ROWNUM = 1
    But this is a very small table, so most of the query returns no data. Additionally I have to check if this number was already selected and ignore it in this case. This isn't a good solution, is it?
    Can somebody help me out with a better solution? Thanks :)

    create or replace package shop_stuff
    is
       function random_number return number;
    end;
    create or replace package body shop_stuff
    is
       function random_number return number
       is
       begin
          return dbms_random.value;
       end;
    begin
       dbms_random.initialize (to_number(to_char(sysdate,'mmddsssss')));
    end;
    create table tbl_special_offers (t_item_id number);
    insert into tbl_special_offers values (1);
    insert into tbl_special_offers values (2);
    insert into tbl_special_offers values (3);
    insert into tbl_special_offers values (4);
    insert into tbl_special_offers values (5);
    insert into tbl_special_offers values (6);
    insert into tbl_special_offers values (7);
    insert into tbl_special_offers values (8);
    insert into tbl_special_offers values (9);
    insert into tbl_special_offers values (10);
    select t_item_id
      from (select t_item_id
              from tbl_special_offers
             order by shop_stuff.random_number)
    where rownum <= 5                       
    SQL> /
    T_ITEM_ID
             6
             7
             5
             4
            10
    SQL> /
    T_ITEM_ID
             1
             5
             3
             9
             6
    SQL> /
    T_ITEM_ID
             6
             5
             3
             2
            10
    SQL> /
    T_ITEM_ID
            10
             2
             8
             4
             1
    SQL>

  • How can I select random records from one column

    How can I random select 400 records from a column contains more than 500,000 records? And how long will it take in oracle? Thanks.

    here is one option: (just change 5 to suit your needs...)
    SQL>select * from (
      2  select object_name
      3  from all_objects
      4  order by dbms_random.random
      5  ) where rownum < 5
      6  /
    OBJECT_NAME
    UTL_SYS_COMPRESS
    GV_$LOG_HISTORY
    GV_$LOGMNR_LOGS
    WWV_FLOW_THEME_7
    SQL>/
    OBJECT_NAME
    WWV_FLOW_UPGRADE_REPORT
    WRI$_ADV_SQLT_STATISTICS_PK
    V_$DATABASE
    GV_$SERVICEMETRIC
    SQL>/
    OBJECT_NAME
    WWV_FLOW_CREATE_FLOW_API
    WRH$_SERVICE_WAIT_CLASS_BL
    EXU8SNAPL
    GV$SERVICEMETRIC_HISTORY
    SQL>                well, regarding how long will it take... it depends from lots of variables...
    Cheers,
    Andrea

  • Help selecting from records with duplicate fields

    Test_table2 is shown below with the sql to create it.
    I need to:
         Identify duplicate address_keys
            Within that set of duplicate address_keys, select only if HH_Income is the same between the two records and the HH_Age difference is less than 10
               Now the duplicate set matches the necessary criteria, and I want to select from these duplicate address_keys, only the one with the most recent verification date
    The purpose of this is to infer cohabiting couples.  In the large set of data we receive, for each HH_key if the people have the same last name they are all listed under the same HH_Key, but if they do not have same last name but live together, they will be listed as separate households (HH_key) but with the same address_key.  A further validator is if each HH_key reports the same HH_Income and if they are close in age.  We then only want to mail to one of the people, so we choose the one that has the most recent verification date.
    The result I would expect here, using the table I provided, would be
    HH_Key
    Address_Key
    HH_Type
    HH_Income
    Age
    Verification_Date
    1234
    1111
    10
    6
    50
    10-Jun-13
    Can you help?
    HH_Key
    Address_Key
    HH_Type
    HH_Income
    Age
    Verification_Date
    1234
    1111
    10
    6
    50
    10-Jun-13
    5678
    1111
    11
    6
    49
    15-Jun-12
    5544
    2222
    10
    6
    65
    10-Apr-13
    7788
    1111
    3
    3
    25
    10-Jun-13
    9898
    3333
    10
    6
    45
    18-Jun-13
    CREATE TABLE test_table2
        (HH_key varchar(20),
         address_key   varchar(20),
         HH_type varchar(2),
         HH_Income varchar(2),
         HH_age varchar(2),
         Verification_date     Date
    INSERT INTO test_table2
    (HH_Key, Address_key, HH_Type, HH_Income, HH_Age, Verification_date)
    VALUES
    (1234, 1111, 10, 6, 50, '10-Jun-13');
    INSERT INTO test_table2
    (HH_Key, Address_key,HH_Type, HH_Income, HH_Age, Verification_date)
    VALUES
    (5678, 1111, 11, 6, 49, '15-Jun-12');
    INSERT INTO test_table2
    (HH_Key, Address_key,HH_Type, HH_Income, HH_Age, Verification_date)
    VALUES
    (5544, 2222, 10, 6, 65, '10-Apr-13');
    INSERT INTO test_table2
    (HH_Key, Address_key,HH_Type, HH_Income, HH_Age, Verification_date)
    VALUES
    (7788, 1111, 3, 3, 25, '10-Jun-13');
    INSERT INTO test_table2
    (HH_Key, Address_key,HH_Type, HH_Income, HH_Age, Verification_date)
    VALUES
    (9898, 3333, 10, 6, 45, '18-Jun-13');

    I really like the results this gave, because it allows me to create a view now that contains the pair in one record.  Thanks for this response.  I think I did post the result that I was looking for which would be the one record that we would mail to:  Once I create the view with one record for each pair, then I would just need to select the verification date that was greatest with the related data.  Would that be the best approach to take?  The fact that I now have a single record for each pair is excellent!
    The result I would expect here, using the table I provided, would be
    HH_Key
    Address_Key
    HH_Type
    HH_Income
    Age
    Verification_Date
    1234
    1111
    10
    6
    50
    10-Jun-13

  • How can I select the random records in u201Cstep loopu201D.

    Hi, Experts,
    I am using step loop to display the data on screen now I want to select the random records from this step loop display. Like 1st 3rd or 5th record, is there any way to select the records,
    like I did in Table control there was a filed in internal table named marked char length 1, I gave this field name in u201Cw/ SelColumnu201D it fill that field with u2018Xu2019 from where I can get the info about the selected records, in this way I can easily perform the operation on that internal table with the help of that marked field.
    Is there any way to select the records in step loop too ?
    Kind Regards,
    Faisal

    thanks for replay shwetali,
    but i just gave you example of random records with 1st 3rd and 5th my goal is not select only these records. i want to select the random mean any records from the step loop display.
    like we can select from the table control. and when select any record it place 'X' in the given internal table field.
    Thanks and kind Regards,
    Faisal

  • Dynamic Table with Random Records

    What I am trying to do is select random records from a table
    and display them in a dynamic table with max columns set to 3 and
    the 4th record to be on a new row. Below is what I have right now
    and it works to randomly pick records but has no function to set
    columns in a table. If there is an easier way feel free to let me
    know. I have tried various ways to do this but none seem to work.
    <CFQUERY NAME="getItems" DATASOURCE="absi">
    SELECT catfit.*, modcats.*, prodmat.*, prod.* FROM catfit,
    modcats,
    prodmat, prod WHERE prodmat.prodid=catfit.prodid And
    catfit.catid=modcats.catid
    ORDER BY modl ASC </cfquery>
    <cfif getItems.recordCount>
    <cfset showNum = 3>
    <cfif showNum gt getItems.recordCount>
    <cfset showNum = getItems.recordCount>
    </cfif>
    <cfset itemList = "">
    <cfloop from="1" to="#getItems.recordCount#"
    index="i">
    <cfset itemList = ListAppend(itemList, i)>
    </cfloop>
    <cfset randomItems = "">
    <cfset itemCount = ListLen(itemList)>
    <cfloop from="1" to="#itemCount#" index="i">
    <cfset random = ListGetAt(itemList, RandRange(1,
    itemCount))>
    <cfset randomItems = ListAppend(randomItems, random)>
    <cfset itemList = ListDeleteAt(itemList,
    ListFind(itemList, random))>
    <cfset itemCount = ListLen(itemList)>
    </cfloop>
    <cfloop from="1" to="#showNum#" index="i">
    <cfoutput>
    <table width="205" border="0" align="left"
    cellpadding="0" cellspacing="0">
    <tr>
    <td width="235" height="116"> <div
    align="center"><img
    src="../Products/ProductPictures/#getitems.pic[ListGetAt(randomItems,
    i)]#" width="100"></div></td>
    </tr>
    <tr>
    <td
    class="ProdTitle">#getitems.brand[ListGetAt(randomItems,
    i)]# #getitems.modl[ListGetAt(randomItems, i)]#</td>
    </tr>
    <tr>
    <td
    class="paragraph">$#getitems.prc[ListGetAt(randomItems,
    i)]#</td>
    </tr>
    <tr>
    <td><A
    href="../Products/details.cfm?prodid=#getItems.prodid[ListGetAt(randomItems,
    i)]#" class="linkcontact">more
    info</a></td>
    </tr>
    <tr>
    <td> </td>
    </tr>
    </table>
    </cfoutput>
    </cfloop>
    </cfif>

    To start a new row after 3 records, do something like this.
    <table>
    <tr>
    <cfoutput query="something">
    <td>#data#<td>
    <cfif currentrow mod 3 is 0>
    </tr><tr>
    </cfoutput>
    </tr>
    </table>
    You should also know that your approach is very inefficient
    in that you are bringing in to cold fusion more data than you need.
    First of all you are selecting every field from 3 tables when you
    don't appear to be using all of them. Second, you are selecting
    every record and you only want to use 3. There are better ways out
    there, but they are db specific and you did not say what you are
    using.

  • Selecting Randoms from Query of Queries

    I can create a query that selects random records
    <cfquery....>
    select top 10 * from table order by newid() <!--- SQL
    Server --->
    </cfquery>
    or
    <cfquery....>
    select top 10 * from table order by rand() limit 10 <!---
    MySQL--->
    </cfquery>
    However, is there a way to cache a query then select random
    records from it?
    I want to cache the overall query that retrieves all the
    records, then
    randomly pull
    from that cached query.
    If I use newid() or rand(), the query bombs on the
    parentheses.
    Any suggestions?
    Tami

    well, it's not really a query of queries... more like a query
    of a cached
    query :)
    "DixieGal" <[email protected]> wrote
    in message
    news:ffsn1b$***$[email protected]..
    |I can create a query that selects random records
    | <cfquery....>
    | select top 10 * from table order by newid() <!--- SQL
    Server --->
    | </cfquery>
    |
    | or
    | <cfquery....>
    | select top 10 * from table order by rand() limit 10
    <!--- MySQL--->
    | </cfquery>
    |
    | However, is there a way to cache a query then select random
    records from
    it?
    | I want to cache the overall query that retrieves all the
    records, then
    | randomly pull
    | from that cached query.
    |
    | If I use newid() or rand(), the query bombs on the
    parentheses.
    |
    | Any suggestions?
    |
    | --
    |
    | Tami
    |
    |

  • Incorrect warning when parsing query with group by clause

    I am using SQL Developer 4.0.0.13.80 with JDK 1.7.0_51 x64 on Windows 8.1
    I have the following SQL, which works perfectly:
    select substr(to_char(tot_amount), 0, 1) as digit, count(*)
    from transactions
    where tot_amount <> 0
    group by substr(to_char(tot_amount), 0, 1)
    order by digit;
    However, SQL Developer is yellow-underlining the first line, telling me that:
    SELECT list is inconsistent with GROUP BY; amend GROUP BY clause to: substr(to_char(rep_tot_amount), 0, 1), substr(to_char(rep_tot_amount),
    which is clearly wrong.
    Message was edited by: JamHan
    Added code formatting.

    Hello,
    I also have found the same issue with the GROUP BY hint. Another problem I found is that the hint suggests to amend the GROUP BY members to add also constant values that are included in the SELECTed columns and whenever those constants include strings with spaces, it generates an invalid query. Normally, constant values won't affect grouping functions and as such they can be omitted from the GROUP BY members, but it seems SQL Dev thinks it differently.
    For example, if you try the following query:
    SELECT d.DNAME, sum(e.sal) amt, 'Total salary' report_title, 100 report_nr
    FROM scott.emp e, scott.dept d
    WHERE e.DEPTNO = d.DEPTNO
    GROUP BY d.DNAME;
    when you hover the mouse pointer on the yellow hint, a popup will show the following message:
    SELECT list inconsistent with GROUP BY; amend GROUP BY clause to:
    d.DNAME, 'Total, 100
    If you click on the hint, it will amend the group by members to become:
    GROUP BY d.DNAME, 'Total, 100;
    that is clearly incorrect syntax. You may notice that after the change the yellow hint is still there, suggesting to amend further the GROUP BY members. If you click again on the hint, you will end with the following:
    GROUP BY d.DNAME, 'Total, 100;
    , 'Total, 100
    and so on.
    I am not sure if this behaviour was already known (Vadim??), but it would be nice if somebody could file a bug against it.
    Finally when writing big queries with complex functions and constant columns, those yellow lines extend all over the select list and they are visually annoying, so I wonder if there is a way to disable the GROUP BY hint until it gets fixed.
    Thanks for any suggestion,
    Paolo

  • Help with selecting 10 random records from all records meeting report selection criteria in Crystal 11

    <p>I am trying to select ten random records from all that match the report selection criteria then report on each of these random records for QA/QI.  I have tried the RND function however it is giving me a random number rather than a random record selection.  I cannot figure this out and am despirately seeking assistance.</p><p>Thank you,</p><p>Amy</p>

    <p>I don&#39;t know of any Random record selection functions but maybe you could write your own custom function inside of a record selection to randomly filter the records.  You would use the Rand function we currently have to decide if a record was included in the report data or not.</p><p>Another possible option is to filter the records before they get to the report.  You can only do this if you are pushing the data into the report instead of having the report pull the data.  An example of this would be passing an ado recordset to a report at runtime. </p><p>Rob Horne</p><p>http://diamond.businessobjects.com/blog/10 </p>

  • How do I select one record when working with image data sets?

    David Powers had an example with creating spry data sets and using the filename in the database linked to images in the local files as data sources.  The pages shows the images with the specified information requested, however all of the images display with their content.  I want to pull an individual record with the image and content. HELP!
    if (!function_exists("GetSQLValueString")) {
    function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
      if (PHP_VERSION < 6) {
        $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
      $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
      switch ($theType) {
        case "text":
          $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
          break;   
        case "long":
        case "int":
          $theValue = ($theValue != "") ? intval($theValue) : "NULL";
          break;
        case "double":
          $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
          break;
        case "date":
          $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
          break;
        case "defined":
          $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
          break;
      return $theValue;
    $maxRows_rs_getPhoto = 10;
    $pageNum_rs_getPhoto = 0;
    if (isset($_GET['pageNum_rs_getPhoto'])) {
      $pageNum_rs_getPhoto = $_GET['pageNum_rs_getPhoto'];
    $startRow_rs_getPhoto = $pageNum_rs_getPhoto * $maxRows_rs_getPhoto;
    mysql_select_db($database_gepps1_db, $gepps1_db);
    $query_rs_getPhoto = "SELECT last_name, first_name, personal_bio, file_name, width, height FROM mem_profile";
    $query_limit_rs_getPhoto = sprintf("%s LIMIT %d, %d", $query_rs_getPhoto, $startRow_rs_getPhoto, $maxRows_rs_getPhoto);
    $rs_getPhoto = mysql_query($query_limit_rs_getPhoto, $gepps1_db) or die(mysql_error());
    $row_rs_getPhoto = mysql_fetch_assoc($rs_getPhoto);
    if (isset($_GET['totalRows_rs_getPhoto'])) {
      $totalRows_rs_getPhoto = $_GET['totalRows_rs_getPhoto'];
    } else {
      $all_rs_getPhoto = mysql_query($query_rs_getPhoto);
      $totalRows_rs_getPhoto = mysql_num_rows($all_rs_getPhoto);
    $totalPages_rs_getPhoto = ceil($totalRows_rs_getPhoto/$maxRows_rs_getPhoto)-1;
    ?>
    <table width="800" border=" ">
      <tr>
        <td>Image</td>
        <td>thumbnail</td>
        <td>firstname</td>
        <td>lastname</td>
        <td>personal bio</td>
      </tr>
      <?php do { ?>
        <tr>
          <td><img src="<?php echo $row_rs_getPhoto['file_name']; ?>" alt="" width="<?php echo $row_rs_getPhoto['width']; ?>" height="<?php echo $row_rs_getPhoto['height']; ?>"></td>
          <td><img src="<?php echo $row_rs_getPhoto['file_name']; ?>" alt="" width="50" height="35"></td>
          <td><?php echo $row_rs_getPhoto['first_name']; ?></td>
          <td><?php echo $row_rs_getPhoto['last_name']; ?></td>
          <td><?php echo $row_rs_getPhoto['personal_bio']; ?></td>
        </tr>
        <?php } while ($row_rs_getPhoto = mysql_fetch_assoc($rs_getPhoto)); ?>
    </table>
    <?php
    mysql_free_result($rs_getPhoto);
    ?>

    I tried pulling the record by using entered value, but then I would need to create several recordsets.
    It's actually no problem doing that.  Can you explain more what you want the final result of this page to display? You are pulling a recordset of the entire group of photos.  Do you still want that comprehensive recordset on this page?  How many other images do you want?  Are you trying to make a master/detail pair where this page displays only the details for a single image?  See what I mean?

  • Selecting a set of records with diff docs but with same docno

    Dear Oracle Gurus
    Consider the following Data
    DocNo Doctype
    ===== ======
    1021 PJ
    1021 TJ
    1022 TJ
    1022 TJ
    1022 PJ
    1023 TJ
    1024 PJ
    1025 PJ
    1026 PJ
    1026 TJ
    1027 PJ
    1028 PJ
    1028 TJ
    As specified there will be transactions involving Doctype PJ alone . and also for certain transactions Doctype PJ and TJ wll be recorded.
    I would like to Select those Docno where there are both PJ and TJ are there leaving out records with doctype PJ alone
    Kindly guide me in this regard. I got confused
    With warm regards
    ssr

    Hi, and Happy New Year!
    Max gave a good solution for the problem you posted. If, in your real data, (docno, doctype) is not unique, why not post some sample data where that combination is not unique?
    You can modify Max's solution to count each doctype only once:
    SELECT       docno
    FROM       mytab
    WHERE       doctype     IN ('PJ', 'TJ')
    GROUP BY  docno
    HAVING       COUNT (DISTINCT doctype)     = 2
    ;The WHERE clause is necessary only if, unlike your sample data, there are other doctypes besides 'PJ' and 'PT'.

  • Grand total (Report footer) issue in a Report with Group selection.

    Hi,
    The case is simple, i have to summrise the NetValue field of a  report at the Group level and at the Report level(Grand Total).
    I also use a Group selection filter (I have grouped my records by MaterialDesc) to keep the desired groups.
    As you already guessed, my group totals are fine but the grand totals(report footer) contain both filtered and non filtered group records. Is there any way to avoid this problem and get a Grand Total from the filtered group records?
    Thank you.

    You can not use standard summaries with Group Suppression you must use either Running Totals or variables.
    In Running Total  evaluate click theformual button and eneter reverse condition to your group suppression.
    If you can not do that then you must use a Var
    In group footer where total is currently correct place a formula like this and suppress it
    @eval
    whileprintingrecords;
    global numbervar RepTot;
    If ..whatever your suppression condition is not true... then reptot:= reptot + sum( valuefield, groupfield);
    In report footer
    @display
    whileprintingrecords;
    global numbervar RepTot;
    Ian

  • Gl  master record with authorization group field, how to download this data

    Dear Experts
    I would like to  down load general ledger master record with the following details.
    gl account   
    text
    authorization group
    i did not find a way to down load this information with the values in the authorization
    group filed.
    submitted for experts advise and help.
    joyal
    Moderator: Please, use standard SAP reports/tables and search before posting

    Dear:
                       Please check
                       S_ALR_87012328 - G/L Account List
                       OB_GLACC13 - Descriptions
                       You can select Auth group from the selection in OB_GLACC13 - Descriptions  and download the same.
                        Regards

  • Alternative to find unique records with 60 character in selection string.

    Hi,
    We have to find out the values from the Infoobject. When we try to display data from an master object, the maximum length of selection it accepts 45 characters only but we need to input data around 60 characters in selection.
    Thing we tried:
    1. Selecting complete data without any condition but it did not work due to large volume of data.
    2. We tried to extract data from RSA3 but it did not work due to large volume of data.
    Please suggest me alternative to find unique records with 60 character in selection string.
    Regards,
    Himanshu Panchal.

    This sounds a bit strange. Are you perhaps mistakenly storing text data incorrectly as the primary key of the master data? I can't think of any actual data that is that length to ensure usinqueness - even GUIDs are maximum 32 characters - but GUIDs don't count as actual "readable" data although you do need to be able to select it from time to time. Perhaps you have a super secure password hash or something like it ?
    Also are you expecting to have a unique single record returned by your selection? To do this would in general REQUIRE that ALL the data is read because master data is not stored in the DB sorted by the data itself, but stored instead sorted by the it's SID.
    When you say you are selecting data from master data, which master data tables are you using? I have been able to select data from very large MD table (15 million unique records) using SE16 with no problems. Just enter the table name, and before you execute just count the number of records - it helps to know what you want to end up with.
    Have you tried using wild cards (the *) to preselect a smaller number of records : * a bit of your 60 character string *
    If you are trying to select from a non-key field you will encounter performance issues, but you can still use the wildcards, and get a result.
    Don't use RSA3 it was designed to make selections and group them into datapackets. It's not the same as selecting directly on the table in SE11 or SE16

  • Send emails from a csv file (grouping records with the same email addresses)

    Writing a script to send emails from a csv which contains record details and email addresses using the Send-Mailmessage cmdlet.
    That part is no trouble, however, the csv file contain records that can have the same email address.
    Is there a way/method I could send the records with the same email address once instead of sending individual email messages?
    Thanks
    Data in the csv file
    Record number, description, email
    1234, Test 1, [email protected]
    5678, Test 2, [email protected]
    1245, Test 3, [email protected]
    4578, Test 4, [email protected]
    $data = Import-csv c:\records.csv
    ForEach($address in $data)
    Send-mailmessage -To $address.emails -from [email protected] -subject "List of records" -Body $data -SmtpServer 192.168.1.1

    The following code does what you are looking for:
    $data = Import-csv c:\records.csv$mx = "192.168.1.1"
    $subject = "List of records"
    $from = "[email protected]"
    $data| Group-Object email|Select-Object Name, @{n='msg'; e={$_.Group| Select-Object -Property "record number", description|ConvertTo-Csv -notypeinformation|Out-String}}|
    ForEach-Object {Send-MailMessage -to $_.Name -Body $_.msg -SmtpServer $mx -Subject $subject -From $from}
    I also recommend no forcing everything into one line.  "One-liner" means "one pipeline" not putting all code on one unreadable line.
    Your code should look like this:
    $data|
    Group-Object email|
    Select-Object Name, @{
    n='msg'; e={
    $_.Group| Select-Object -Property "record number", description|
    ConvertTo-Csv -notypeinformation|Out-String
    }|
    ForEach-Object {
    Send-MailMessage -to $_.Name -Body $_.msg -SmtpServer $mx -Subject $subject -From $from
    Now we can see the code and see that you are still unnecessarily converting back and forth.
    To get the group look at how I did it.
    $body=$_.Group | Format-Table |Out-String
    Isn't that much easier?
    Once you master the pipeline these things will become second nature.  In PowerShell it is not necessary to write lots of code most of the time.
    ¯\_(ツ)_/¯

Maybe you are looking for

  • Why is it do hard to get a straight answer on Mac security?

    I have the latest OS, Yosemite.  I don't download anything illegally or use software I don't trust.  I basically only use my computer for personal reasons and limit what websites I go to and visit.  I have gone to the apple store and talked to the st

  • Using "Number Only" yet still "Chapter" in Portrait Index

    I am using iBooks Author for a collection of short stories so I'd like to eliminate the word "chapter" from the "chapter" page which is displayed in Portrait mode. I used the "Number only" feature to eliminate the word "chapter" from the heading of e

  • HT5275 Problems with safari on mountain lion

    I have installed Mountain Lion yesterday. Safari was crashing as soon as I tried to open it. Now I have removed the file Extensions from the Library and everything seems to be fine.

  • T420 Fan noise

    I just bought a T420 a couple of days ago, and am rather surprised by the constant fan noise (level) after having read that it is very quiet. The fan runs constantly with a noise level that is much higher than other notebooks I've used (maybe noisy i

  • Web Service Job options timeout not saving

    I'm using ver. 6.0.3.140 When I create a new WebService job it defaults the Timeout(in seconds) to 75.  I can edit the field but after I save and reopen the Job it still says 75.  If I run a job it completes but in the output it says "Read timed out"