locked
Sql query extra column with extra effect RRS feed

  • Question

  • I have list of columns in select list ,i am trying to include one more column.After adding the column it the result was changed with more number of records.if we have excluded that column from select list the result was coming fine.
    Friday, April 25, 2014 8:17 AM

Answers

  • From the explanation it seems you've a GROUP BY clause which on adding one more column is increasing number of records in resultset. This will happen when column added have multiple values within the group. If your intention is to keep resultset recordset the same you've two options

    1. Apply some kind of aggregation like MIN,MAX etc over the column. So in that case you'll effectively return only single value of the column per hroup

    2. If you want to retrieve all values use a rowset concatenation method as below and add it also to GROUP BY clause

    http://visakhm.blogspot.in/2014/01/rowset-concatenation-with-special.html


    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

    • Proposed as answer by Naomi N Friday, April 25, 2014 5:01 PM
    • Marked as answer by Fanny Liu Tuesday, May 6, 2014 1:54 AM
    Friday, April 25, 2014 8:32 AM

All replies

  • Are you adding new tables to get these new columns?

    please post your query and table schema

    Friday, April 25, 2014 8:28 AM
  • From the explanation it seems you've a GROUP BY clause which on adding one more column is increasing number of records in resultset. This will happen when column added have multiple values within the group. If your intention is to keep resultset recordset the same you've two options

    1. Apply some kind of aggregation like MIN,MAX etc over the column. So in that case you'll effectively return only single value of the column per hroup

    2. If you want to retrieve all values use a rowset concatenation method as below and add it also to GROUP BY clause

    http://visakhm.blogspot.in/2014/01/rowset-concatenation-with-special.html


    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

    • Proposed as answer by Naomi N Friday, April 25, 2014 5:01 PM
    • Marked as answer by Fanny Liu Tuesday, May 6, 2014 1:54 AM
    Friday, April 25, 2014 8:32 AM