SELECT 4 latest rows from Oracle table with join

huddds

I'm quite new to Oracle so I'm not totally familiar with the ROWNUM statement. I'm trying to get the latest 4 articles from my table. I'm getting 4 results but they are 2012 articles even though my date ordering is set to DESC. Any help would be great.

Oracle query:

SELECT bt.article_id, ba.* 
FROM articles_types bt 
LEFT JOIN blog_articles ba 
ON ba.article_id = bt.article_id 
WHERE ROWNUM < 5 
ORDER BY Published DESC
jarlh

Just a wild guess, but order the result before rownum limit:

select t.* from
(
SELECT * 
FROM articles_types bt 
LEFT JOIN blog_articles ba 
ON ba.article_id = bt.article_id 
ORDER BY Published DESC
) T
WHERE ROWNUM <= 4 

This worked, the issue was a duplicate column name

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Select distinct rows from a table with an inner join

From Dev

join single value from one table to multiple rows table - Oracle

From Dev

Select rows from table by id of a left join table

From Dev

Doctrine - select last 4 rows from table

From Dev

Doctrine - select last 4 rows from table

From Dev

pdo select latest from table

From Dev

Laravel 4 - Join table but only latest row

From Dev

Laravel 4 - Join table but only latest row

From Dev

Oracle, LEFT OUTER JOIN not returning all rows from left table, instead behaving like INNER JOIN

From Dev

select rows which has latest date without repetition from two joined table?

From Dev

select every 4 rows in table

From Dev

Retrieving the latest record from a Table (Oracle SQLPlus)

From Dev

Select random 4 rows using inner join

From Dev

Oracle select random rows from table based on criteria in another table (Stratified Sampling)

From Dev

Oracle SQL: Select rows from table A with fallback to joined table A and B. (union, group by,...)

From Dev

select a random rows from table

From Dev

Select random rows from table

From Dev

Select clustered rows from a table

From Dev

Select latest from joined table excluding duplicates

From Dev

select latest duplicate record from table MySQL

From Dev

MYSQL: select latest record only (on left join table)

From Dev

How to group rows and select latest date to display in a data table

From Dev

Select rows from specific date with left join

From Dev

Select values from different rows in a mysql join

From Dev

Select latest rows

From Dev

MySQL - Join & Count rows from another table

From Dev

Join Rows from one huge SQL Table

From Dev

MySQL JOIN one of the rows from second table

From Dev

Delete rows from table inner join

Related Related

  1. 1

    Select distinct rows from a table with an inner join

  2. 2

    join single value from one table to multiple rows table - Oracle

  3. 3

    Select rows from table by id of a left join table

  4. 4

    Doctrine - select last 4 rows from table

  5. 5

    Doctrine - select last 4 rows from table

  6. 6

    pdo select latest from table

  7. 7

    Laravel 4 - Join table but only latest row

  8. 8

    Laravel 4 - Join table but only latest row

  9. 9

    Oracle, LEFT OUTER JOIN not returning all rows from left table, instead behaving like INNER JOIN

  10. 10

    select rows which has latest date without repetition from two joined table?

  11. 11

    select every 4 rows in table

  12. 12

    Retrieving the latest record from a Table (Oracle SQLPlus)

  13. 13

    Select random 4 rows using inner join

  14. 14

    Oracle select random rows from table based on criteria in another table (Stratified Sampling)

  15. 15

    Oracle SQL: Select rows from table A with fallback to joined table A and B. (union, group by,...)

  16. 16

    select a random rows from table

  17. 17

    Select random rows from table

  18. 18

    Select clustered rows from a table

  19. 19

    Select latest from joined table excluding duplicates

  20. 20

    select latest duplicate record from table MySQL

  21. 21

    MYSQL: select latest record only (on left join table)

  22. 22

    How to group rows and select latest date to display in a data table

  23. 23

    Select rows from specific date with left join

  24. 24

    Select values from different rows in a mysql join

  25. 25

    Select latest rows

  26. 26

    MySQL - Join & Count rows from another table

  27. 27

    Join Rows from one huge SQL Table

  28. 28

    MySQL JOIN one of the rows from second table

  29. 29

    Delete rows from table inner join

HotTag

Archive