How to ORDER BY Different column than in the group by clause.

Hello, I have this sql statement
SELECT COUNT([Tags]) AS CNT, [Tags]
FROM [Tags], [Images]
WHERE
([Images].[Tags] LIKE '%' + [Tags].[LongTag] + '%') AND
([Tags].AllowTagPost = 'True' )
GROUP BY [Images].[Tags]
HAVING COUNT([Tags]) > 30
ORDER BY [Tags].[LastTagPost] DESC
It returns the tags, the number of occurances sorted by count.  However, I want to sort it by a column in the Tags table named LastTagPost (DATETIME)  The idea is to get the tag that hasn't been used in the longest time and also has more occurances
than 30 in the image table.  When I try to order by this column i get an error that i'm sure most of you are all to familer with.
Error:
Column "Tags.LastTagPost" is invalid in the ORDER BY clause because it is not contained in either an aggregate function or the GROUP BY clause.
Any help would be greatly appreciated.

Couldn't you just include the LastTagPost as a MIN?
DECLARE @tags TABLE (LastTagPost DATETIME, LongTag VARCHAR(100), allowTagPost CHAR(5))
DECLARE @images TABLE (tags VARCHAR(10))
SELECT COUNT(i.Tags) AS CNT, i.Tags, MIN(t.LastTagPost) AS lastTagPost
FROM @Tags t
INNER JOIN @Images i
ON i.Tags LIKE '%' + t.LongTag + '%'
WHERE t.AllowTagPost = 'True'
GROUP BY i.Tags
HAVING COUNT(i.Tags) > 30
ORDER BY LastTagPost DESC
Don't forget to mark helpful posts, and answers. It helps others to find relevant posts to the same question.

Similar Messages

  • How to order by a column not on the base table?

    Best explained by example:
    I have 1 block, base table is SALE. I would like to sort this block by PROD_DESCRIPTION which is not on SALE. I only have PROD_CODE (the primary key of PRODUCT which contains PROD_DESCRIPTION)
    I am not running Enterprise Edition so I cannot create a view and use Instead-of triggers.
    I would rather not have to re-write all my triggers because I want the default base table behaviour that forms provides.
    Any ideas?
    Cheers,
    Tim.

    Hey tim,
    I also had a similar problem.
    You need to create a function in the database with an associated
    pragma to specify the level of purity of the function
    WNDS (write no database state)
    WNPS (write no package state)
    PRAGMA RESTRICT_REFERENCES(fn_get_dname, WNDS, WNPS);
    Function fn_get_dname (p_empno in number) return varchar2 is
    v_dept_name varchar2(40);
    begin
    select dname into v_dept_name
    from dept, emp
    where dept.deptno = emp.deptno
    and emp.emp_no = p_emp_no;
    return v_dept_name;
    end;
    order by in a block based on the emp table (assuming you want a list of employees by department name)
    order by fn_get_dname(empno), empno
    Hope that will help you to solve your problem.
    Thanks
    Pranati

  • Hi, when typing on my macbookair keyboard, i get a different text than on the keyboard - for exemple, typing "t", i get "t(". Any clue how to solve that? Thanks a loy

    Hi, when typing on my macbookair keyboard, i get a different text than on the keyboard - for exemple, typing "t", i get "t(". Any clue how to solve that? Thanks a lot

    Correct - another example, when i type "1" it writes "A1".
    Hope this helps?

  • More than 1 column in the group by clause

    DB Version:10gR2
    I understand the basics of GROUP BY clause. I have a question on why we have on more than 1 columns in GROUP BY clause.
    In the below example, the course name by itself does not make up a group. A Course name plus its BeginDate make up a group. This is the whole point of having more than 1 columns in the GROUP by clause. Right?
    SQL> select r.course, r.begindate , count(r.attendee) as attendees
      3   from registrations r
      4   group by r.course, r.begindate
      5   order by course
      6  /
    COURSE BEGINDATE      ATTENDEES
    JAVA    12/13/1999           5
    JAVA    2/1/2000             3
    OAU     8/10/1999            3
    OAU     9/27/2000            1
    PLS     9/11/2000            3
    SQL     4/12/1999            4
    SQL     10/4/1999            3
    SQL     12/13/1999           2
    XML     2/3/2000             2

    ExpansiveMind wrote:
    Thanks Dmorgan. I am just learning the basics of GROUP BY clause. I have noticed that all Non-aggregate columns in SELECT list have to be present in the GROUP BY clause. I thought it was a "syntactical requirement". Now, i realise that these columns are present in the GROUP BY clause because only a combination of columns make up a group.Well, it is a bit of both actually. It is a syntactic requirement that all non-aggregated columns in the select list must appear in the group by clause. However, the non-aggregated columns in the select list is what defines your group. Your two examples define two different groups, and would answer two different questions.
    John

  • How to sync 2 different Mac users using the same Apple ID and with out mixing each other info?

    How to sync 2 different Mac users using the same Apple ID and with out mixing each other info?
    We are two people using three difrent Macs, 1 Iphone and 1 Ipad with separate USERS  on each Mac but sharing the same Apple ID: xxxxxx
    I set up the first user to iCloud and it was OK but when I set up the second user to use iCoud the first users's info gets mixed with the second user's info?
    Do we have to set up a diffrent Apple ID for each other?
    Sometime ago I added my friends E mail (yyyyy) to the main Apple ID (xxxx) as for using his E mail account (to separate our e mail accounts, and it's working ok) but now when I try to create a new apple ID whith the same friend's e mail (yyyyyy)  it says that his mail (yyyyy) is already an apple ID when the Apple ID is really my E mail (xxxxx)... any clue?
    Thanks

    I believe because you migrated from a Nokia to an iPhone you need to register the Bn phone number with your Apple ID so it can be used for iMessage. The Pn number seems to be the only one registered
    Go here > https://appleid.apple.com/cgi-bin/WebObjects/MyAppleId.woa/
    Manage your Apple ID and see if that does the trick
    Hope that helps

  • Primarily using the ipad air as an art portfolio but photos i upload in order get rearranged. other than changing the date they were shot, is there any solution to this? can they be reorganized in iphoto on the ipad?

    primarily using the ipad air as an art portfolio but photos i upload in order get rearranged. other than changing the date they were shot, is there any solution to this? can they be reorganized in iphoto on the ipad?

    You are welcome.
    Sorting and organizing photos on IOS devices is one of the things that really need to be improved. It looks like the developers simply did not expect the users to want to keep large photo libraries on an IOS device, where the ordering would matter. I'd send feedback to the developer team, so that they see, what the users want and need:
    You can use this form:  Apple - iPhoto - Feedback

  • Basic, basic question - how to order prints from more than one album at onc

    I am having two problems with iphoto - I would be most grateful for any help. First, when I go to upload my photos to a web-based printing company (like shutterfly or snapfish), and I click on the vendor's "browse" photos to find the album to upload, the way the photos come up does not correspond to my album titles in iphoto, so I can't find them. I have my photos sorted in labeled albums, and would like to upload them as such, but when I click on iphoto library, it brings up all kinds of other files that don't correspond to my current file labels. Can anyone help?
    Equally irritating, when I use apple's "order print" features, it only lets me order from one album at a time. I'd like to order from multiple albums all at once, without paying shipping for each one. Any ideas? Again, most grateful for any advice.

    Hi, Sestew, and welcome to Apple Discussions.
    Problem 1: Export the photos you want printed from iPhoto to a folder on the desktop. Use the printer's browser to navigate to that folder and upload them to the printing company from it. After uploading them, trash the folder that contains the exported copies. The pictures are still safe in your iPhoto library.
    Problem 2: Create a new album and place all the pictures you want printed in it. (A photo can appear in any number of albums, so doing this won't remove any of the pictures from the other albums they're already in.) Then order that album printed. Delete the album after ordering, if you wish — the pictures will remain in whatever other albums you've placed them in.

  • How to set up different virtual LANs (using the E3200)?

    Hi.
    I would like to set up different virtual LANs (using the E3200) so that I can have two different networks that can't access each other.
    The E3200 is connected to a modem for internet access.
    I would like both networks to have access to the internet.
    Does the E3200 alone support creating virtual LANs?
    If not, is there another way I can meet the requirement using the E3200 alone (using something other than virtual LANs)?
    I'm ultimately thinking that I would need at least one other router.
    So for example,
    Router A (E3200) is connected to the modem and setup for DHCP using a LAN IP range 192.168.1.1/24.
    Router B is connected to Router A and setup for DHCP using a LAN IP range 192.168.2.1/24.
    In this way devices connected to Router A should not have access to devices connected to Router B and visa-versa, correct?  For example, Device X connected to Router A cannot ping or browse files on Device Y connected to Router B and visa-versa, correct?
    Would I need to setup anything else on Router B?  For example, do I need to setup DNS settings so that devices connected to Router B can connect to the internet without issue?  Would I need to specify that these virtual LANs are not bridged, and on which router, or both?
    I already know how to set up a static IP, DHCP, LAN IP ranges, and static DNS settings on a router, etc.
    In regards to wireless devices, I am thinking they would follow the same pattern; so wireless devices connected to Router A (E3200) have access to other wired and wireless devices connected to Router A but not to wired or wireless devices connected to Router B and visa-versa.  However, if wireless devices currently don't have access to wired devices also connected to Router A, then that is fine for now.
    Thank you very much!
    -Rami
    Solved!
    Go to Solution.

    The E3200 has no VLAN support according to the manual. There's no way to configure two separate networks with this router alone.
    You will need to add network electronics.
    Ex:
    Managed Switch with VLAN
    Another wireless router with VLAN
    If your modem supplies multiple public or private IP addresses then you could put a switch after the modem and two wireless routers attached to the switch.
    Please remember to Kudo those that help you.
    Linksys
    Communities Technical Support

  • How can i select other column values('-' separated) in group by function

    CREATE TABLE EMP (
         EMPNO NUMBER(4) NOT NULL,
         ENAME VARCHAR2(10),
         JOB VARCHAR2(9),
         SAL NUMBER(7)
    INSERT INTO EMP(EMPNO, ENAME, JOB, SAL) VALUES (7369, 'SMITH', 'CLERK', 800);
    INSERT INTO EMP(EMPNO, ENAME, JOB, SAL) VALUES (7499, 'SMITH', 'SALESMAN', 1600);
    INSERT INTO EMP(EMPNO, ENAME, JOB, SAL) VALUES (7521, 'ALLEN', 'SALESMAN', 2400);
    In Output I want 3 columns : EMP,SUM(SAL),JOB(hyphenSeparated)
    Means i want my output like
    First row : SMITH,2400,CLERK-SALESMAN
    Second row : ALLEN,2400,SALESMAN
    I tried to write following sql : select ename,sum(sal) from emp group by ename
    But i want other colummn value in '-' separated. but group by is only allowing agreegated function.
    How can i select other column value using group by function.

    SQL>  select ename,sum(sal), listagg(job, '-') within group (order by job) as job  from emp group by ename;
    ENAME        SUM(SAL) JOB
    ALLEN            2400 SALESMAN
    SMITH            2400 CLERK-SALESMANnote: LISTAGG is a feature of 11.2

  • How to define a dynamic column to count the quarter of each year?

    Lets see the result that now displayed:
    YEARS MONTHS SUMMONTH SUMYEAR SUMQUARTER
    2009 Jan      127994 1766166     449652
    2009 Feb      168106 1766166     449652
    2009 Mar      153552 1766166     449652
    2009 Apr      160329 1766166     438913
    2009 May      137605 1766166     438913
    2009 Jun      140979 1766166     438913
    2009 Jul      148606 1766166     435283
    2009 Aug      150390 1766166     435283
    2009 Sep      136287 1766166     435283
    2009 Oct      149529 1766166     442318
    2009 Nov      153268 1766166     442318
    2009 Dec      139521 1766166     442318
    2010 Jan      124670 1721212     407181
    2010 Feb      139278 1721212     407181
    2010 Mar      143233 1721212     407181
    2010 Apr      149518 1721212     444112
    2010 May      152292 1721212     444112
    2010 Jun      142302 1721212     444112
    2010 Jul      149125 1721212     412855
    2010 Aug      130328 1721212     412855
    2010 Sep      133402 1721212     412855
    2010 Oct      157754 1721212     457064
    2010 Nov      137078 1721212     457064
    2010 Dec      162232 1721212     457064
    The problem is about how to dynamic a new column called "Q_count" to count each displayed row belong to which quarter of year??
    In addition, it will repeat again from next year.
    For example:
    *2009 Jan-Mar will display "q1", Apr-Jun will display "q2".....and for 2010 Jan-Mar, it will display "q1" again and so on.*
    Here is my sql that I am using:
    select years,months,summonth,sumyear,sumquarter
    from(
    select years,months,summonth,sumyear,
            sum(sumhour) over(partition by years || to_char(ym, 'Q') order by years || to_char(ym, 'Q')) sumquarter,ym
    from(
    select years, months, days, hours, mins, sumHour, SUM (sumHour) OVER (PARTITION BY years,months,days) sumDay, SUM (sumHour) OVER (PARTITION BY years,months) sumMonth, SUM (sumHour) OVER (PARTITION BY years) sumyear,
    to_date(years || months, 'YYYYMon', 'NLS_DATE_LANGUAGE=American') ym
    from (SELECT x.years, x.months, x.days, x.hours, x.mins, sum(x.value) as sumHour
    FROM xmltest,
    XMLTABLE ('$d/cdata/name' passing xmldoc as "d"
       COLUMNS
      years integer path 'year',
      months varchar(3) path 'month',
      days varchar(2) path 'day',
      hours varchar(2) path 'hour',
      mins varchar(2) path 'minute',
      value float path 'value'
      ) as X
      group by x.years, x.months, x.days, x.hours, x.mins
      order by x.years, x.months, x.days
      group by years,months,summonth,sumyear,sumquarter,ym
      order by ymThanks everyone helps me!!!

    If my understanding is correct..
    select years,months,summonth,sumyear,sumquarter,qtr
    from(
            select years,months,summonth,sumyear,to_char(ym, 'Q') qtr,
                    sum(sumhour) over(partition by years || to_char(ym, 'Q') order by years || to_char(ym, 'Q')) sumquarter,ym
            from(
                    select   years, months, days, hours, mins, sumHour,
                             SUM (sumHour) OVER (PARTITION BY years,months,days) sumDay,
                             SUM (sumHour) OVER (PARTITION BY years,months) sumMonth,
                             SUM (sumHour) OVER (PARTITION BY years) sumyear,
                             to_date(years || months, 'YYYYMon', 'NLS_DATE_LANGUAGE=American') ym
                    from  (
                            SELECT x.years, x.months, x.days, x.hours, x.mins, sum(x.value) as sumHour
                            FROM xmltest,
                                 XMLTABLE ('$d/cdata/name' passing xmldoc as "d"
                                            COLUMNS
                                              years integer path 'year',
                                              months varchar(3) path 'month',
                                              days varchar(2) path 'day',
                                              hours varchar(2) path 'hour',
                                              mins varchar(2) path 'minute',
                                              value float path 'value'
                                           ) as X
                            group by x.years, x.months, x.days, x.hours, x.mins
                            order by x.years, x.months, x.days
    order by ymEdited by: jeneesh on Mar 26, 2012 5:49 PM
    Removed unnecessary GROUP BY

  • How to call two different servlet-url in the same application

    Hi,
    I want to call, consecutively these methods in my application.
    response.sendRedirect(servlet-url1)
    reponse.sendRedirect(servlet-url2)
    but the second method dont answer,
    I think, the first method redirect s with response ,
    but how to call two different servlet ?
    thanks

    if you call the first redirect, the servlet is getting aborted, so you can redirect to the first servlet, working the stuff in it, and then in the second servlet you can redirect to the third servlet

  • How to sync two different Nano's through the same iTunes?

    how do I upload two persons different runs through the same iTunes?
    My wife and I have two different Nanos and seperate sensors but we use the same iTunes which is in my name. Now I have made a new Nike account for my wife but how can I sync her run? At the moment it automaticaly syncs with my account?
    regards
    Morten Timm

    if you call the first redirect, the servlet is getting aborted, so you can redirect to the first servlet, working the stuff in it, and then in the second servlet you can redirect to the third servlet

  • How can i dynamically select columns based on the input parameter?

    I have an input parameter which takes single numeric value.
    Based on this value i have to dynamically select table-columns .
    For eg: if i have following fields in my table :
    SEM_1
    SEM_2
    SEM_3 and SEM_4.
    And if i give numeric input as 2 , then i have to select "SEM_2" column only.
    if the input is 3 then i have to select "SEM_3" only and leave the rest of the columns.
    how do i achieve this dynamic feature in the "Select .....  From...... table...." statement in the ABAP??

    Hi,
    you should try something like this.
    TYPES: cond(72) TYPE c.
    data: condtab TYPE TABLE OF cond,
             condw type cond.
    data: lv_field(30) type c value 'SEM_'.
    write p_num to lv_field+4(1).
    condw = lv_field.
    append condw to condtab.
    SELECT (CONDTAB) FROM table INTO.....
    Kostas
    Message was edited by:
            Kostas Tsioubris

  • How can I add a column to show the website (web site) of an rss feed?

    I've got a lot of rss feeds coming into thunderbird. I organized some into folders, but also have a folder for several rss feeds as they adress the same topics and I prefer not to browse through 25 separate folders. However, the sender doesn't always make it clear which blog it's from, so I'd like to add a column which shows the website of the rss feed. (sender is often: [email protected], and there are different writers for a single blog who themselve have their own blog as well, so can't sort on sender name either).
    When opening an rss feed, it displays in the header: web site (with the space) and then the web adress. This is what I'd like to be able to see in my columns.
    I didn't see an option yet to customize columns, nor did I find an addon that does this.
    Does anyone know a solution?

    Thanks, that seems to work. I'm struggling to place the lightbox at the top of the page however - when I click the trigger I want the menu image to display anchored to the top of the page, but there's always a gap as it centers the image. Help is appreciated!

  • How to refer to a column name in the domain constraint

    When we specify a check constraint (for SQL Server) within a domain we need to enter some syntax expression, for example
    len(phone) > 7
    Later the modeller will put exactly this expression into SQL code. But this would be wrong as constraint should refer to a column name in the table (which would not be "phone").
    So how to make Data modeler to put a real column name within domain constraint?

    Thank you very much, it really works!
    However I would like to know where I can get documentation on such internal variables (like %COLUMN%)? I find it difficult to locate this information in the Help file attached to a modeler (it seems that it only describes UI screens).

Maybe you are looking for

  • Address Book contact list display

    The issue is not Lion exclusive but a general Address Book "feature" The contacts categorizing by the first letter finishes with Z, i.e. it works only for the English alphabet. All contacts in Russian go under "#" category which is extremely inconven

  • IDOC filter at Field / Segment Level

    Hi Can you please tell me how to set an IDOC filter at field and segment level in short? Thanks

  • PCI-6229 Digital I/O sample clock problem

    Hi, I am using PCI-6229. I need to use digital output channel to generate 20KHz 30%duty cycle pulses. The datasheet shows DO sample clock frequency can be 1M Hz. But in may application, only 100KHzTimebase can work to generate. But acctually I need a

  • Maximum characters allowed in Edit Box, how to set?

    I have an Edit Box in a screen designed using screen painter. I want to restrict the user not to type more than 20 characters. Is there any properties available in the Edit Box, like set max length = 20 ? BTW i am using 2004.2B

  • Dual table

    I have tries two queries - Select rownum from dual connect by level <=7 it gives me 7 rows as 1 2 3 4 5 6 7 Bur when i give Select rowid from dual connect by level <=7 it is giving- AAAAECAABAAAAgiAAA AAAAECAABAAAAgiAAA AAAAECAABAAAAgiAAA AAAAECAABAA