Select distinct('more than one column') from ....

Why does this sql statement not work:
select distinct(column_a, column_b, column_c), empno
from emp;
How can I 'select distinct' using more than one column.

Actually, DISTINCT applies to all columns in the result.
Distinct is not a function, you cannot do distinct(column1, column2, ...).
As a matter of fact it doesn't make sense to expect distinct applies to only one column, because you do not specify any criteria on how to select the values for the second column.
A final note: you can do distinct(column1), column2, but this will still apply to both columns!
Here're some examples that will all return both rows from the set, where set is: (1,1), (1,2):
select distinct val1, val2
from
select 1 as val1, 1 as val2 from dual
union all
select 1 as val1, 2 as val2 from dual
select distinct val1||'-'||val2
from
select 1 as val1, 1 as val2 from dual
union all
select 1 as val1, 2 as val2 from dual
select distinct(val1), val2 -- this is very misleading. distinct still applies to both columns
from
select 1 as val1, 1 as val2 from dual
union all
select 1 as val1, 2 as val2 from dual
Edited by: user4010726 on Dec 1, 2009 11:06 AM
Edited by: user4010726 on Dec 1, 2009 11:07 AM

Similar Messages

  • Select Distinct (More than one column)

    Hi All,
    I have the following SQL statement written in MySQL that returns only one row per MODCODE with the associated DEPTCODE of AE:
    SELECT DISTINCT
    EL_MODULE.DEPTCODE, EL_MODULE.MODCODE, EL_MODULE.MODNAME, EL_MODULE.MODLEVEL, EL_DEPTLEVEL.DEPTLEVELHEADER
    FROM EL_DEPTLEVEL, EL_MODULE
    WHERE EL_MODULE.MODLEVEL = EL_DEPTLEVEL.LEVELCODE AND EL_MODULE.DEPTCODE='AE' ORDER BY EL_MODULE.MODLEVEL
    However when I attempt to use this in oracle it returns three rows, could somebody point out what it is I need to change to get this working correctly in oracle.
    Hope someone can help.
    Jon

    Duplicates? No way! This query returns unique comibination of
    EL_MODULE.DEPTCODE,
    EL_MODULE.MODCODE,
    EL_MODULE.MODNAME,
    EL_MODULE.MODLEVEL and
    EL_DEPTLEVEL.DEPTLEVELHEADER
    Cheers
    Sarma.

  • Selecting/importing more than one clip from camcorder using check boxes

    Hi.
    I've just bought a new camcorder (SD Card) based. I used to use Mini DV tapes.
    Now when I import into iMovie9 I am able to select which clips I import. I always choose manual import because I like to save different clips into different topics.
    I am able to uncheck all the clips and individually select each one I want to import but I'm baffled about how to select more than one clip at a time and then check the import box. e.g. select clips 3 to 15 and then having to check the box once instead of checking ever box for each clip. There must be something like hold shift down while selecting but I've not managed to work it out yet!
    Any help is appreciated.
    Thanks
    Paul

    Hi Paul,
    I import clips as you do - by manually ticking the box in each clip. Like you, I haven't figured out a way to select a group of clips in one go - that would be very handy! Sorry I can't help - I'll be interested to see what answers you get.
    John

  • ALV to select more than one column by row using set_table_for_first_display

    Hello everyone,
    I am developing an application (ALV OO) to select more than 1 column by row ( one ). This is an a holiday application so the idea is:
    -One column will be the day, and the row will be the user.
    So I am trying to select more than one day by user (that would be the row).
    I am using the method set_table_for_first_display but when it shows the alv, doesn't let me to select more than one column with a click of the mouse.
    Does anybody know if I can do this (select more than one column, by row) in somehow?
    Please let me know if you need more clarification about this.
    Thanks in advance
    Diego

    Hi Diego,
    it's all in the documentation.
    set different selection modes through the value of the field u201CSEL_MODEu201D in the layout structure.
    SPACE
    same as 'B'
    see 'B'
    Default setting
    'A'
    Column and row selection
    Multiple columns
    Multiple rows
    The user selects the rows through pushbuttons at the left border of the grid control.
    'B'
    Simple selection, list box
    Multiple columns
    Multiple rows
    'C'
    Multiple selection, list box
    Multiple columns
    Multiple rows
    'D'
    Cell selection
    Multiple columns
    Multiple rows
    Any cells
    The user selects the rows through pushbuttons at the left border of the grid control
    Beyond setting this option, you can set u201CNO_ROWMARKu201D option to hide the mark column which is normally visible when the selection mode allows multiple row selection.
    One point to notice here is that if you set your ALV Grid as to be editable, it may override your selection mode regardless of your layout settings.
    This is from SDN Community Contribution "An Easy Reference for ALV Grid Control" By: Serdar ŞİMŞEKLER
    Sorry, no link,. it's on my disk.
    Regards,
    Clemens

  • Fetching more than one row from a table after selecting one value from the dropdown

    Hi Experts,
    How can we fetch more than one row from a table after selecting one value from the dropdown.
    The scenario is that I have some entries in the dropdown like below
      A               B               C        
    11256          VID          911256  
    11256          VID          811256
    11256          SONY      11256
    The 'B' values are there in the dropdown. I have removed the duplicate entries from the dropdown so now the dropdownlist has only two values.for eg- 'VID' and'SONY'. So now, after selecting 'VID' from the dropdown I should get all the 'C' values. After this the "C' values are to be passed to other methods to fetch some data from other tables.
    Request your help on this.
    Thanks,
    Preeetam Narkhede.

    Hi Preetam!
    I hope I understand your request proberly, since this is more about Java and less about WebDynpro, but if I'm wrong, just follow up on this.
    Supposed you have some collection of your original table data stored in variable "origin". Populate a Hashtable using the values from column "B" (let's assume it's Strings) as keys and an ArrayList of whatever "C" is (let's assume String instances, too) as value (there's a lot of ways to iterate over whatever your datasource is, and since we do not know what your datasource is, maybe you'll have to follow another approach to get b and c vaues,but the principle should remain the same):
    // Declare a private variable for your Data at the appropriate place in your code
    private Hashtable temp = new Hashtable<String, ArrayList<String>>();
    // Then, in the method you use to retrieve backend data and populate the dropdown,
    // populate the Hashtable, too
    Iterator<TableData> a = origin.iterator();
    while (a.hasNext()) {
         TableData current = a.next();
         String b = current.getB();
         String c = current.getC();
         ArrayList<String> values = this.temp.get(b);
         if (values == null) {
              values = new ArrayList<String>();
         values.add(c);
         this.temp.put(b, values);
    So after this, you'll have a Hashtable with the B values als keys and collections of C values of this particular B as value:
    VID --> (911256, 811256)
    SONY --> (11256)
    Use
    temp.keySet()
    to populate your dropdown.
    After the user selects an entry from the dropdown (let's say stored in variable selectedB), you will be able to retrieve the collection of c's from your Hashtable
    // In the metod you handle the selection event with, get the c value collection
    //and use it to select from your other table
    ArrayList<String> selectedCs = this.temp.get(selectedB);
    // now iterate over the selectedCs items and use each of these
    //to continue retrieving whatever data you need...
    for (String oneC : selectedCs) {
         // Select Data from backend using oneC in the where-Clause or whatever...
    Hope that helps
    Michael

  • How can I select more than one song from the search results?

    I want to create playlists based on certain words in the song title. For example, I may want to create a playlist of all my songs with LOVE in the title.
    Doing the search is easy, but I can't select more than one song at a time. Is there any way in iTunes 12 for Windows to do this? I found an answer in iTunes for Mac, and it basically says to "un-check "Search Entire Library." " but I don't see that option in iTunes for Windows.
    Here is the link to that question: how can i select more than one song from drop down search bar
    I hope some Windows user can help me out.

    Found the "Search Entire Library" option - click on the small (VERY small for my eyesight) down arrow next to the magnifying glass. Also need to select "Filter by: Songs", and then the songs in the main window show the results.
    I'm going to leave this up on the board because 1) in case someone else has this question, and 2) I don't know how to delete it anyway.

  • More than one column retrieved in "report and form" page

    HELLO!
    let's see if anybody can help me with this... i'm sure it's a stupid problem but i really don't know how to solve it.
    when i create a new application with APEX, i want to add a "report and form" page. i select the table where de data is, and then click on add page. then i go to the page definition for the form that just has been created but there's no option for selecting more than one column as the link column...
    i mean, i want to show a report with all the columns from the table and then, by selecting one of them, the form should display that column but the problem is that the primary key of the table is formed by 6 columns and i always receive the "more than one column retrieved" message as it's trying to retrieve the information using only one column. is there any way to make the link column be composed by 6 or 7 columns??

    APEX can handle 2 primary key for one table (if you are using the automated fetch row and the automated process row).
    In your case, you'll have to create your own "fetch process (page rendering)" and "DML process (page processing)".
    Flex
    Homepage : http://www.insum.ca
    InSum Solutions' blog : http://insum-apex.blogspot.com

  • Can I have one cell in a table extending over more than one column?

    I'd like to be able to have a table in which some cells extend over more than one column.
    In Word, I can just delete the right hand cell border, and the cell automatically stretches over the next column.
    (Pages 5.2.2.)
    Thanks

    Pages v5 is not an MS Word clone, and therefore, it doesn't matter what you did in Word. Select the adjacent table column cells, and then either two-finger tap, or right-click and choose merge cells from the contextual menu.

  • LOV Return To More Than One Column

    Hello,
    How could I return LOV values to more than one column?
    I created a dynamic LOV based on sql statement. I would like to return more than one values to multiple columns in my page.
    E.g. When user selects employee number name, department and location to return to respective columns.
    Any help is highly appreciated.
    I am using APEX 3.2.0.
    Thanks

    hi,
    Below link might help you.
    http://rutgerderuiter.blogspot.com/2008/10/update-multiple-items-from-lov-field.html

  • How to create combobox to display more than one columns

    I need kind help with the following question. As the combobox includes two pieces--textbox and the combobox list. Then how to create a combo box bean, which is based on table EMP(empno number(6), ename varchar2(40)) records for example, to achieve these features:
    1) allow more than one columns to be displayed in its records list--e.g., I need to show these records:
    empno (value) ename (label)
    103 David M Baker
    104 David M Baker
    105 Kelly J Volpe
    106 Krista F Carpenter
    107 Michelle P Silverman
    The two 'David M Baker's are different employees, but unfortunately, with the same name.
    2) allow combo box list to return the column value 'empno' even though it shows both columns as above. i.e., if user picks the second record above, then the combobox list returns 104 to the textbox in the background, but the 'David M Baker' is displayed on the textbox. Of course the combobox list may return 'David M Baker' if needed when there is only one column in the list as the current standard feature.
    3)allow partial match search by typing in some letters. i.e., if user types in the textbox of the combobox letter 'K' or 'k' then the partially matched records
    105 Kelly J Volpe
    106 Krista F Carpenter
    should be automatically displayed in the combobox list, not the whole list as above; then user may double click to choose one of the two or if user continues to type in 'R' or 'r', then the uniquely matched record 'Krista F Carpenter' is displayed in the textbox and the 106 is returned to the textbox.
    4) as a bonus if it's doable, allow combobox to return values to different textboxes when its records list has more than one columns.
    The reason I need these features is that I am working on the project migrated from Microsoft Access applications to centralized Java version web application. We at beginning promised to users community that Java swing will provide all the GUI user friendly features Microsoft Access has, but now we got stucked--we ate our words and got tons of complains from our users community. This is just the most needed component I posted here. I really hope that Java would add all the default GUI user-friendly features to compete with MS since its Win95 GUI has been accepted as industry standard. And most users are used to it. They claimed that they don't know and don't care what tool you use the newly created application should be more user friendly, not the opposite.
    I would be very much appreciated if any one would help me with this item.

    Thanks for your comments. I think nobody expects Sun to write everything including special features for its components. But I do think Sun should provide at least those standard user-friendly features for the GUI components because most users have been used to the GUI user-friendly features provided by Win95 and Access/Excel applications. Then this will help us to productively create applications to beat MS applications.
    Other wise like me, to get the existing GUI features, existed in old MS Access application, for our migrated Java application, I must re-create the GUI components library first which is a big burden to me at least, for others it might be fun for coding on their own from scratch, but I have to focus on the timing of project.
    If you really can pass the request to Sun and push them move a bit, please pass these words: before Sun starts to revise them, please play around window GUI, e.g., Access/Excel applications, then plan what to do, the bottom line is to equally match or better than them in FUNCTIONALITY(Look and feel is not my focus here). Don't ignore the influence of Windows regardless of you hate it or love it, the reality is most users are so familiar with windows GUI features which are accepted as industry standard. Thus the choice is to match or better to beat them. Don't make your car by closing your door, don't assume users will like what you come out in a closed room.

  • How to email more than one photo from camera roll

    How do e-mail more than one photo from the camera roll at a time?

    Go to the camera roll, open the thumbnails, click on the arrow in the top right, select up to 5 photos, click on share in the top left and select email.

  • One Key FIgure in more than one column with different restrictions

    Hi,
      I am using a key figure in more than one column with different restrictions, but restriction in one column is affecting the result in other column. What shall i do to make it independent from one another??

    Hi Pravender Chauhan,
        If you want in Single column different value for different Rows based on same Key Figure, you can create Structure where you can define different logic for each row but using same key figure.
    If you want to use different Key figures then you should have to Restricted Key Figure and for any calculation you can use calculated Key figure.
    Assign points if Useful.
    Regards,
    Rajdeep.

  • Can I manage more than one iTouch from one PC?

    A family member has an iTouch managed with iTunes on PC. Another family member would like an iTouch but does not have a computer.
    Can one manage more than one iTouch from one PC? How? Does one install separate instances of iTunes somehow on the PC for each device?
    There is also the desire to have separate Apple Store accounts for each device. We don't what synced devices.

    *How to use multiple iPods with one computer*
    The Apple support document How to use multiple iPods with one computer suggests a number of ways. I use method two (Sync with selected playlists) with a slight twist. Rather than regular playlists I set the grouping field to indicate which users should receive which tracks and create smart playlists based on the content of this field.
    e.g.
    "Alice's Tracks" is "Grouping contains Alice" + "Kind contains audio"
    "Bob's Videos" is "Grouping contains Bob" + "Kind does not contain audio"
    Tracks that both Alice & Bob want on their iPods have the grouping set to "Alice/Bob"
    etc.
    I currently manage our family's five iPods using this system, each getting a different selection to suit their tastes and the capacity of their iPod. An advantage of using the grouping field is that it is stored in file tags (for non-wav audio files anyway) so that it is relatively easy to recreate the playlists should the iTunes library get trashed. Also useful if you move files about manually as playlist membership is preserved when you delete & re-import the tracks.
    tt2

  • Crystal Report - More than one table from MySql

    Hello, I am in need of help big time.
    I have am using Visual Studio 2010 and Crystal Report 10.
    The problem that I am incounting is that I am unable to retreive data from more than one table from a MySql database. I have been stuck on this for too long and need to hjump the hurdle.
    I am using a MySql connection string, a dataset and a crystal report which is based on the dataset.
    The main error that I am having is, the browser opens and a form appears saying "The report you requetsed requires further information" With the Server name: DataSetPropertiesDetials, while the User name and Password fields are then enabled.
    I am guessing I am missing something in my code.
    When I retreive data from one table the report is fine, but when I try to use more than one table it throws the error.
    My Code is below and also attached:
    Imports System.Data.SqlClient
    Imports System.Configuration
    Imports MySql.Data.MySqlClient
    Imports CrystalDecisions.ReportSource
    Imports CrystalDecisions.Web
    Imports CrystalDecisions.CrystalReports.Engine
    Imports CrystalDecisions.Shared
    Public Class _Default
    Inherits System.Web.UI.Page
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    Dim con As MySqlConnection
    Dim rpt As New CrystalReport3()
    Dim myReport As New ReportDocument
    Dim myData As New DataSet
    Dim cmd As New MySqlCommand
    Dim cmdUser, cmdProperty, cmdBranch As New MySqlCommand
    Dim daBranch, daProperty, daUser As New MySqlDataAdapter
    con = New MySqlConnection()
    'Connection String
    con.ConnectionString = "Server=****;Database=***;UID=***;Password=****"
    Try
    con.Open()
    cmdBranch.CommandText = "SELECT branch FROM tblbranch"
    cmdBranch.Connection = con
    daBranch.SelectCommand = cmdBranch
    daBranch.Fill(myData)
    cmdProperty.CommandText = "SELECT ref, keys_held, key_no, keys_out, no_name, address_line1, address_line2,key_label FROM tblproperty"
    cmdProperty.Connection = con
    daProperty.SelectCommand = cmdProperty
    daProperty.Fill(myData)
    cmdUser.CommandText = "SELECT known_name FROM tbluser"
    cmdUser.Connection = con
    daUser.SelectCommand = cmdUser
    daUser.Fill(myData)
    myReport.Load("REPORT LOCATION")
    myReport.SetDataSource(myData)
    myReport.Database.Tables(0).SetDataSource(myData.Tables(0))
    CrystalReportViewer1.ReportSource = myReport '
    Catch myerror As MySqlException
    MsgBox(myerror.Message)
    End Try
    End Sub
    End Class

    Hi, 
    You have 3 SQL commands but you are calling SetDataSource only once.  You need to look through for each of the SQL Commands. 
    Good luck,
    Brian

  • Simple request... More than one column to organize tracks?!

    Is it possible to organize tracks with more than one column, such as 'name' followed by 'comment', for example.. The way I have it now, each time you click on a new header, the last header cannot be used in combination, i.e. only the currently selected header can be used. Thanks!

    strangelittleman,
    I don't know of any way to do this, but I agree it would highly useful. (Like the sorting algorithms in word processors that let you sort by column 2 followed by column 6, etc., or whatever.)
    Here is a work-around. If the column you use to arrange your songs, say song name, produces a fairly sizable listing for the same song (Louie Louie, for instance) and you want to organize that by artist name (to group the multiple versions done by Motorhead or IGGY POP, for instance), then just select the songs of a given name and copy them to a new playlist. Then select the artist name column to organize by that.
    This is clumsy, and only useful if you have a large number of songs in the first sorting category (song name in the example above) and duplicates that you wish to detect in the second sorting category (artist name in the example above). But in some cases it may be helpful.
    Drake

Maybe you are looking for

  • My MacBook pro will not connect to the internet, be it via the airport or ethernet at any location.

    I have been on the phone with tech support, and have been to the Apple Store 3 times already. Each time I have brought the computer to the store, the internet will work. The workers say the store is 'magic.' However upon leaving the Apple store, the

  • Does anyone have an issue with the adobe files jumping around?

    I recently purchased a new Mac Pro running Mountain Lion and installed the latest CS6 upgrade. I've been working with with for a few weeks and notice that while I'm in adobe files (mostely InDesign) the pages will jump around or scroll without prompt

  • Export raw excel dato to fill-able PDF

    Hi Guys Im new to the forum and this is my first thread - I really hope you can help me (sorry for my english, its been a while since i've been using it). I would like to be able to export raw data from Excel to a PDF file, which is fill-able / edita

  • Open downloaded files on linux

    After files have downloaded, in the Downloads dialog, whether I right-click and select "open contaning folder" or simply "Open", firefox tries to open the selected file (or folder) in gedit, which of course gives an error. Why doesn't firefox follow

  • Dataguard - logical standby - need help - not updating data at commit

    Hi Need help ? We have logical standby setup where data is not updated at standby when committed at Primary. It only updates when alter system swith logfile. On Primary: log_archive_dest_2='service=xxStandby LGWR ASYNC valid_for=(online_logfiles,prim