Select most recent post

Hello everyone,
I have 2 tables:
- FORUM_MESSAGE
ID | ID_FORUM | ID_USER | TITLE | DATE
1 1 1 post 1 10/11/2005
2 2 2 post 2 09/10/2005
3 1 1 post 1 08/06/2005
- FORUM_USER
ID | ID_TYPE | NAME
1 1 admin
2 2 user
What i need to get is the most recent TITLE of each forum posted by an admin.
This is what i have done, but it is not working:
SELECT FORUM_MESSAGE.TITLE
FROM FORUM_MESSAGE, FORUM_USER
WHERE FORUM_MESSAGE.DATE = (SELECT MAX(FORUM_MESSAGE.DATE)
               FROM FORUM_MESSAGE GROUP BY FORUM_MESSAGE.ID_FORUM)
AND FORUM_MESSAGE.ID_USER = FORUM_USER.ID
AND FORUM_USER.ID_TYPE = 1
Could someone help me? i am lost...
Thanks in advance

but still does not compile If it does not compile there must be a compilation error. Please use cut'n'patse to snip your code and the results from SQL*Plus. Like this
SQL> CREATE TABLE forum_user (id number, type number, name varchar2(10))
  2  /
Table created.
SQL>
SQL> INSERT INTO forum_user VALUES (1, 1, 'admin')
  2  /
1 row created.
SQL> INSERT INTO forum_user VALUES (2, 2, 'APC')
  2  /
1 row created.
SQL>
SQL> CREATE TABLE forum_message (id number, forum_id number, user_id number , title varchar2(30), pd
ate date)
  2  /
Table created.
SQL>
SQL> INSERT INTO forum_message VALUES (1, 1, 1, 'post #1' ,to_date('10/11/2005', 'DD_MM-YYYY'))
  2  /
1 row created.
SQL> INSERT INTO forum_message VALUES (2, 2, 2, 'post #2', to_date('09/10/2005', 'DD_MM-YYYY'))
  2  /
1 row created.
SQL> INSERT INTO forum_message VALUES (3, 2, 1, 'post #3', to_date('08/06/2005' ,'DD_MM-YYYY'))
  2  /
1 row created.
SQL>
SQL> SELECT fm.title
  2  FROM forum_message fm, forum_user fu
  3  WHERE fm.pdate = (SELECT MAX(sq.pdate)
  4                                    FROM forum_message sq
  5                                    WHERE sq.forum_id = fm.forum_id)
  6  AND fm.user_id = fu.id
  7  AND fu.type = 1
  8  /
TITLE
post #1
SQL> Cheers, APC

Similar Messages

  • Select "most recent" records in abap

    Hi
    how can I select the most recent records in a table by using the abap select statement.
    Example: The 100 rows with the "highest" (most recent) sequence-numbers in a table with documents.
    somehow like this:
        SELECT "most recent" * FROM draw
        INTO TABLE gt_doklist
        UP TO 100 ROWS
        where ...
    Has anybody an idea?
    Thanks in advance,
    Willi

    Actually I believe that all the answers are wrong.
    I believe that there will never be a single statement. If you need to determine the last 100 records for a special user you first need to determine the highest document number.
    this can be done by
    select max( document_number ) into document_number from table where username = username.
    Any descending sorting order or group by etc. will never make sure that you get the last one. For a simple reason What should the select statement look like that makes sure (in combination of any cursor applied)? Its impossible!
    If you now need the latest 100 records for a single user its the same problem like buffered number ranges. There is no way to perform that task because there is no database routine or sql statement to do so. And 1.5 million records are too much to try out or select everything.
    You could do an assumption that the last 100 for that user have been posted during the last 1000 or last 10.000 records, select them and filter out.
    Alternative you can perform the following select statement for 100 times. Using an index on document number and user might not be such a performance killer if its only done for one user during his online dynpro process:
    data: max_number type char10.
    select max( documentnumber ) into max_number from table
      where username = username into [structure].
    max_number = max_number + 1.
    do 100 times
    select max( documentnumber ) from table intomax_number
      where username = username and docnumber lt max_docnumber.
    select * from [db_table] into [structure] where docnumber = max_number.
    append [structure] to [table].
    enddo.
    Of course that just draft coding... apply if statements and so on...
    Even though its pretty poor, its the only way to do. Any select statement will never garantee what records you will get if you do not restrict accordingly and if the restriction has to be made on document number, but if there is no way to get the max_number - [100 last records of this user], there is no solution using one statement.
    Thats it.
    Edited by: Rob Burbank on Feb 25, 2010 8:52 AM

  • How to see most recent posts per forum

    Hi, all;
    It seems to me that I'm not "getting" something about the organization of the forums. What I want to do is see the posts in each forum that I am interested in, most recent first. What I actually see when I go to each forum is "trending" discussions. When I go to Browse>Discussions, I can see that some of the most recent discussions aren't getting into the "Trending" category, but Browse>Discussions shows a jumbled mess of all forums.
    I'd like to help these people, but I fear their questions are falling through the cracks, since they're not "trendy" enough for me to be able to see them.  How can I see "recent" discussions instead of "trending" ones.
    Regards;
    Amy

    Hi Amy, you might not have gotten a lot of responses posting in the forum dedicated to community help. Next time, for forum-related questions, rather use this page: http://forums.adobe.com/community/general/forum_comments?view=discussions

  • Select most recent DATE for an ID.

    Hi All,
    I need to SELECT the records with the most recent DATE for each ID. A DATE range is part of the selection criteria.
    My data.
    MY_ID MY_DATE
    1684662 26-JAN-09
    1424097 27-JAN-09
    1684663 27-JAN-09
    1684664 27-JAN-09
    1684672 28-JAN-09
    0689073 28-JAN-09
    1052476 21-JAN-09
    1052476 21-JAN-09
    1360828 23-JAN-09
    1684661 23-JAN-09
    1052476 30-JAN-09
    1052476 30-JAN-09
    1052476 30-JAN-09
    1052476 30-JAN-09
    The code below works fine when selecting 1 ID in the SUBSELECT, but with multiple ID it still selects rownum=1 (of course). This as far as my thinking takes me.
    SELECT my_id,
    my_date
    FROM
    (SELECT my_id,
    my_date
    FROM my_table
    ORDER BY my_date DESC
    WHERE rownum = 1
    AND *{color:#ff0000}my_id = 1052476{color}*
    AND TO_CHAR(my_date,'YYYY/MM/DD') BETWEEN '2009/01/01' AND '2009/01/31';
    If I could somehow pass the SELECT ID into the SUBSELECT WHERE clause I should have this done.
    Any suggestions?
    Thank You in Advance for Your help,
    Lou

    One of many possible soultions.
    ME_XE?with data as
      2  (
      3     select 1684662 as id, to_date('26-JAN-09','dd-mon-yyyy') as the_date from dual union all
      4     select 1424097 as id, to_date('27-JAN-09','dd-mon-yyyy') as the_date from dual union all
      5     select 1684663 as id, to_date('27-JAN-09','dd-mon-yyyy') as the_date from dual union all
      6     select 1684664 as id, to_date('27-JAN-09','dd-mon-yyyy') as the_date from dual union all
      7     select 1684672 as id, to_date('28-JAN-09','dd-mon-yyyy') as the_date from dual union all
      8     select 0689073 as id, to_date('28-JAN-09','dd-mon-yyyy') as the_date from dual union all
      9     select 1052476 as id, to_date('21-JAN-09','dd-mon-yyyy') as the_date from dual union all
    10     select 1052476 as id, to_date('21-JAN-09','dd-mon-yyyy') as the_date from dual union all
    11     select 1360828 as id, to_date('23-JAN-09','dd-mon-yyyy') as the_date from dual union all
    12     select 1684661 as id, to_date('23-JAN-09','dd-mon-yyyy') as the_date from dual union all
    13     select 1052476 as id, to_date('30-JAN-09','dd-mon-yyyy') as the_date from dual union all
    14     select 1052476 as id, to_date('30-JAN-09','dd-mon-yyyy') as the_date from dual union all
    15     select 1052476 as id, to_date('30-JAN-09','dd-mon-yyyy') as the_date from dual union all
    16     select 1052476 as id, to_date('30-JAN-09','dd-mon-yyyy') as the_date from dual
    17  )
    18  select id, the_date
    19  from
    20  (
    21     select id, the_date, max(the_date) over (partition by id) as max_the_date
    22     from data
    23  )
    24  where the_date = max_the_date;
                    ID THE_DATE
                689073 28-JAN-0009 12 00:00
               1052476 30-JAN-0009 12 00:00
               1052476 30-JAN-0009 12 00:00
               1052476 30-JAN-0009 12 00:00
               1052476 30-JAN-0009 12 00:00
               1360828 23-JAN-0009 12 00:00
               1424097 27-JAN-0009 12 00:00
               1684661 23-JAN-0009 12 00:00
               1684662 26-JAN-0009 12 00:00
               1684663 27-JAN-0009 12 00:00
               1684664 27-JAN-0009 12 00:00
                    ID THE_DATE
               1684672 28-JAN-0009 12 00:00
    12 rows selected.
    Elapsed: 00:00:00.03

  • How to select Most recent record with rest of record in ascending order...?

    Dear Expert,
    I have one table called Tab1 & have a lot columns. For this schenario, i mentioned few of the columns.
    The columns are
    product_type varchar2(100),
    curr_date date (storing with time stamp),
    other1_cloumn varchar2(10),
    other2_cloumn varchar2(10)
    Now I want to display all the records in ascending order except most recent record for every product_type || Union all || Most recent records in ascending order in single query.
    For example...
    product_type curr_date date other1_cloumn other2_cloumn
    1, "10-May-2005 10:10:10", 10, 10
    1, "10-May-2005 10:10:11", 10, 10
    1, "10-May-2005 10:10:12", 10, 10
    1, "10-May-2005 10:10:09", 10, 10
    2, "10-May-2005 10:10:10", 10, 10
    2, "10-May-2005 10:10:11", 10, 10
    2, "10-May-2005 10:10:12", 10, 10
    2, "10-May-2005 10:10:09", 10, 10
    3, "10-May-2005 10:10:10", 10, 10
    3, "10-May-2005 10:10:11", 10, 10
    3, "10-May-2005 10:10:12", 10, 10
    3, "10-May-2005 10:10:09", 10, 10
    Now I want to display (OUTPUT) like...
    1, "10-May-2005 10:10:10", 10, 10
    1, "10-May-2005 10:10:11", 10, 10
    1, "10-May-2005 10:10:09", 10, 10
    2, "10-May-2005 10:10:10", 10, 10
    2, "10-May-2005 10:10:11", 10, 10
    2, "10-May-2005 10:10:09", 10, 10
    3, "10-May-2005 10:10:10", 10, 10
    3, "10-May-2005 10:10:11", 10, 10
    3, "10-May-2005 10:10:09", 10, 10
    1, "10-May-2005 10:10:12", 10, 10
    2, "10-May-2005 10:10:12", 10, 10
    3, "10-May-2005 10:10:12", 10, 10
    Plz, provide a solution....

    I want to display like...
    select * from tab1 where (product_type,curr_date) in
    (select product_type,max(curr_date) from tab1 group by product_type)
    order by product_type
    Union All
    (select * from tab1 where (product_type,curr_date) NOT IN
    (select product_type,max(curr_date) from tab1 group by product_type)
    order by product_type)
    But, In the above case, The ORDER BY Clause will not work...How to get this one...?
    I mean.. I want to display all the records in ascending order except Most recent record base on Product type and next I want to display Most recent record in ascending order. I want to display both cases in a single query...?

  • Select Most recent Occurance

    Hi Friends,
    I have a strange requirement where in we need to select the most recent occurance of a record based on 2 columns, consider the below sample data:
    C1     C2     C3
    1234     0     abc
    1234     1     abc
    1234     0     def
    1234     1     def
    1345     20     fgh
    1345     30     fgh
    1345     20     ijk
    1345     30     ijk
    now i need to write a select statement which returns the following result
    C1     C2     C3
    1234     0     def
    1234     1     def
    1345     20     ijk
    1345     30     ijk
    we need to pick data from the recent occurance of the columns C1 and C2.
    Please help me. Do let me know in case you need any thing.
    Thanks.

    Of course rowid not near always guarantees that:
    SQL> drop table t;
    Table dropped
    SQL> create table t as (
      2  select 1234 C1, 0  C2, 'abc' C3 from dual)
      3  /
    Table created
    SQL> alter table t minimize records_per_block;
    Table altered
    SQL> insert into t
      2  select  1234, 1, 'abc' from dual union all
      3  select 1234, 0, 'def' from dual union all
      4  select 1234, 1, 'def' from dual union all
      5  select 1345, 20, 'fgh' from dual union all
      6  select 1345, 30, 'fgh' from dual union all
      7  select 1345, 20, 'ijk' from dual union all
      8  select 1345, 30, 'ijk' from dual
      9  /
    7 rows inserted
    SQL> select * from t;
            C1         C2 C3
          1234          0 abc
          1345         30 ijk
          1234          1 abc
          1234          0 def
          1234          1 def
          1345         20 fgh
          1345         30 fgh
          1345         20 ijk
    8 rows selected
    SQL> select * from t where rowid in(
      2     select max(rowid) over(partition by c1,c2 order by null) from t
      3  );
            C1         C2 C3
          1234          0 def
          1234          1 def
          1345         30 fgh
          1345         20 ijk
    SQL> There is no guarantee that Oracle will insert your rows with continuously growing rowids especially if you have blocks with deleted rows, ASSM tablespaces etc. The only guarantee is to use some sequence column, because as I understand rows are inserted from flat file and therefore datetime also may be inappropriate due to the fact that rows can be inserted faster than datetime increases.
    See also this thread where a person had similar problem Row is changing position - ON INSERT
    Gints Plivna
    http://www.gplivna.eu

  • Select most recent record prior to a target date

    Let's say I have a set of unique records with the following dates:
    11/15/08
    11/30/08
    Is it possible to select only the most recent record prior to a user-entered target date (e.g., 12/1/08)?  So in this case, only the record dated 11/30/08 would be selected for the report.

    Use the record selection formula like this
    {Date field}<={?Date Parameter}
    And also wrtite the group selection formula like this
    {Date field}=maximum({Date field})
    This returns the recent value nearer to the date entered in the prompt.
    Regards,
    Raghavendra

  • Report on most recent posting date

    Hi experts,
    My report needs to show the fields profit center and its posting date.posting date should have a selection variable for the user to enter a key date.The report should show only the last posting date for every profit center before the key date.
    my doubt is that the data in the infoprovider should be compared to get the last posting date. is it possible to read the data and get the recent posting date in the customer exit for the variable on posting date.
    Please suggest the possible ways of doing this.

    Hi Krishna,
    The recent posting date for the profit centre can not be stored as a transaction data in the cube and it can not be derived in the customer exit.
    You have to add a date field as the master data attribute of profit centre and populate that from the transaction cube data to get last posting date for each profit centre.
    You can then show is as the nav attaribute of profit centre in the report.
    Thanks,
    Krishnan

  • Select most recent date only

    I'm quite new to discoverer so please bear with me.
    I have a query that returns e.g. 16 records.
    One of the fields is a date field.
    What I want to do is put a condition on the date field so that it only returns the record with the most recent date.
    Thanks.

    let me explain it to u in detail
    i have the following fields
    CONTRACTNUM FIRMTYPE FIRM A FIRM B FIRM % NTP_ACTUAL
    123456 P ABC XXX 96 MM/DD/YYYY
    S XXX DEC 4 MM/DD/YYYY
    P ABC XXX 96 MM/DD/YYYY
    S XXX DEC 4 MM/DD/YYYY
    Here the CONTRACTNUM IS unique and the firm% sum is equal to 100, but the record is repeating twice , under the same CONTRACTNUM......................any suggestions willbe of great help.
    So for this i used the ROW_NUMBER() OVER(ORDER BY date_field DESC)
    in my case : ROW_NUMBER() OVER(ORDER BY ntp_actual DESC).
    Now it gives me a new field with the row_numbers and when i create a condition where the calculation is =1, it give me one record
    I was using this , because for any given contract number .............it should bring the record with the recent ntp_actual date.
    i hope i was clear.
    Thnks

  • How do I get these threads to open at the most recent post?

    This is most annoying: every time I get an email notifying me that there's a new post in a thread I'm following, when I click on the link to go to that thread it sends me to the TOP of the thread and not to the post I was clicking about.
    What am I doing wrong and how do I correct this?

    Well,  I tried it with your post, Klaus, and it seemed to work correctly. Maybe it's just me. When I see an invitation in the email to click on a link to REPLY to a message, I don't click on it, because I don't want to reply to that message. I just want to read it. I might THEN want to reply to it  but I also might not. Maybe I'm just stupid that way.
    In future, I'll pretend to myself that I actually want to REPLY to every post for which I receive a notification.
    But each time I do that, I'll think about the cutlery drawer in the kitchen at Cupertino, and I'll wonder if all the knives in there are perfectly sharp.
    Thanks, folks.

  • Select most recent file and display

    I've been considerig this and I am closer to how I expect it to work
    This is what I have so far but can't peice together just yet.
    Get the current open folder window look for the last item if shot within the last 30 secs of the creation date, if shot within 30 secs then select/highlight the file and use system events to press keystroke y using cmd and option down.(to put it on the screen in full screen) Display for 15 secs, or if esc hit then wait for next file to arrive and so on.
    If the window is closed of the current open folder then end applescript.
    This is how far I have got but can't link the ideas together well.
    set theWindow to name of front window of application "Finder"
    set theWindow to name of front window of application "Finder"
    set theFldr to path of theWindow
    tell application "Finder"
              set theContents to sort items of theFldr by creation date
              set theLastimage to (contents of item 1 of theContents) as text
      --is it within the last 30 seconds?
      -- yes, then
              tell application "System Events"
      keystroke "y" using {command down, option down}
                        delay 15
      key code 53
      --then wait for arrival of next image. and repeat.
      --if theWindow is close end applescript.
              end tell
    end tell

    Hi,
    If you don't want to use a folder action, try this :
    try
          tell application "Finder" to set currFolder to name of front Finder window
    on error
          return -- no Finder window
    end try
    set tDate to (current date) - 30
    repeat
          set b to false
          tell application "Finder"
                set fWindows to Finder windows whose it's name is currFolder
                if (fWindows is not {}) then
                      set tWind to item 1 of fWindows
                      set nFiles to document files of tWind whose creation date > tDate -- get newer files
                      set tDate to (current date)
                      if nFiles is not {} then
                            reveal nFiles
                            my selectionfullScreen(currFolder, count nFiles)
                            set b to true
                      end if
                else
                      exit repeat -- quit the script, the current Folder is closed
                end if
          end tell
          if not b then delay 5 -- no recent files, wait 5 seconds
    end repeat
    on selectionfullScreen(tName, n)
          tell application "System Events"
                tell process "Finder"
                      set frontmost to true
                      keystroke "y" using {command down, option down}
                      repeat (15 * n) times
                            tell window 1 to if (exists) and (its title is tName) then return -- the user close QuickLook
                            delay 1
                      end repeat
                      tell window 1 to if (exists) and (its title is not tName) then key code 53 -- close QuickLook after (15 seconds X (number of images))
                end tell
          end tell
    end selectionfullScreen

  • Discussions most recently posted in dont move to the top?

    Hi,
    Again here to ask if anyone else is seeing this or is it just me?
    The issue basicly seems to be that someone has answered to a thread they started -> I answered -> they answered. Yet the discussion doesnt come to top the first page. This thread in questions is still located at the third page.
    See anything with the following picture?
    The post I am referring to is the third from the bottom. All the previous discussions havent had any posts in 6 days. Yet this one has one reply from 16min ago and still lurks at the 3rd page of the Firewall Discussion section.
    Also, I cant see any automatic notification email from the CSC in my work mail at the moment regarding this post.
    - Jouni

    I do not understand what you mean about two libraries. Can you post a screen shot?
    Maybe this will help with your problem
    If you  have iTunes 11 turn on the Sidebar. Go to iTunes>View and click on Show Sidebar. You can also do a Crtl+S to show the sidebar. The sidebar is where Devices appears. and Control+B to show the Menu bar
    iTunes 11 for Windows: Syncing overview
    iTunes 11 for Windows: Set up syncing for iPod, iPhone, or iPad

  • Select statement for most recent value in a table

    Hi all,
    I need  to select most recent value from a table . I dont have any date or time field in that table . Can one help me in this issue

    Hi,
    Just check this thread:
    how to determine most recent date from the date column of internal table
    U will find the solution here.
    Regards,
    Kumar

  • SQL to compare 2 most recent rows in table

    Hi,
    I am trying to compare STATUS fields ( Most recent to Next Most recent )
    and select Most recent row if there STATUS values are different.
    SQL :
    select c.id,c.effdt,c.end_dt,c.status
    from table c ,table k
    where c.id = k.id
    and c.status <> k.status
    SAMPLE DATA
    ID EFFDT END_DT STATUS
    6 10/10/2006 12/31/9999 Y
    6 10/01/2006 10/09/2006 N
    6 09/02/2006 09/30/2006 Y
    EXPETING O/P
    6,10/10/2006 , 12/31/9999 , Y
    but with the above SQL i am getting 3 rows with same data .
    6,10/10/2006 , 12/31/9999 , Y
    6,10/10/2006 , 12/31/9999 , Y
    6,10/10/2006 , 12/31/9999 , Y
    is there a way to select only one row without using DISTINCT ?
    i can't use DISTINCT keyword because if sample data contains
    below data my SQL compares 1st row and 4th row since STATUS are not
    equal and returns results which we dont want . we just want
    to compare Most recent and next most recent ( i.e first and second rows
    only )
    SAMPLE DATA
    ID EFFDT END_DT STATUS
    6 10/10/2006 12/31/9999 Y
    6 10/01/2006 10/09/2006 Y
    6 09/02/2006 09/30/2006 Y
    6 08/01/2006 09/01/2006 N
    Best regards,
    Karru

    Try this
    SELECT *
    FROM
         (SELECT end_dt,
              status,
              lead(status) over(PARTITION BY id
            ORDER BY end_dt DESC) AS
           next_status
            FROM qry
            ORDER BY end_dt DESC)
    WHERE NVL(status,'Z') <> next_status
    AND rownum = 1

  • Abap Query on most Latest Posting Date in G/L Account

    Dear All
    This is the new request that has come from the client. What they want to see is the G/L account and the most recent Posting Date. For eg Lets say that 220000 has 3 line items
    1000 in march 06
    2000 in april 06
    3000 in may 06
    End user wants to see Balance as 6000 and the most recent Posting date as may 06. If i Pull Accounting Doc # and Posting Date it will give me all the details and date which i dont really want. How do i do it ?
    Please help me
    Thanks
    Sameer

    Hi,
    what we can do is that get all the line items for a G/L account in an internal table. Sort it descending by date. Pick the first row's date and then simply sum up the quantities.
    Hope this helps.
    Regards,
    Himanshu.

Maybe you are looking for

  • Using aliases in where clause

    I am using the following query for as part of my effort select b.account_number, b.restriction_code, a.cusip_number, a.symbol, c.shares, round(((c.shares/nullif(to_number(a.shares_outstanding),0))*100),4) outstanding_share_percent from br_securities

  • IPHOTO '09 won't start after update

    Hi Group: I've got a white MacBook I haven't used in several months, as I mostly use my MBP. Tonight I fired up the MB and started iPhoto '09 to check out the geotagging functions, which I haven't tried before. The app started and directed me to upda

  • Help with ios 4.2 update!

    Cannot also update with message "the iPad software update server could not be contacted" This happens after downloading ios 4.2 and trying to install it. Thanks

  • Can you use Virtual Channels in a Borland C++ program using the NiDAQ library? It would make configuration of my application much easier.

    I have no idea which category this fits under. Could you please CC any replies to [email protected]

  • Won't start up.. blue screen

    My wife did a software update last night, (her ibook G4 is on 10.4), and now the iBook won't start up. We get the grey screen and the Apple symbol then after a while it goes to a Blue screen, then just stays on a blue screen. I've reset the PRAM and