2

How do I return all rows from a table except the first row. Here is my sql statement:

SELECT * FROM article  where article_no 
NOT IN
(SELECT * FROM article   order by article_no  limit 1)

The up given SQL query throws an error:

This version of MariaDB doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'

2 Answers2

1

The subquery must select only the column you need for comparison:

SELECT *
FROM article
WHERE article_no NOT IN (
    SELECT article_no
    FROM article
    ORDER BY article_no
    LIMIT 1
)

The above query will work in MySQL, but not in MariaDB, which doesn't currently support LIMIT in subqueries. I would rewrite the subquery like this:

SELECT *
FROM article
WHERE article_no NOT IN (SELECT MIN(article_no) FROM article)
Sonny
  • 8,204
  • 7
  • 63
  • 134
  • 1
    Not that I am overly bothered, but that is kinda.. well very very very like my comment – RiggsFolly Dec 20 '17 at 19:58
  • 1
    Hmmm my comment has been there for 9 minutes before your answer was posted! I guess you must be a slow typer – RiggsFolly Dec 20 '17 at 20:01
  • 1
    @RiggsFolly - I read the question, but not the comments. I wrote an answer because there wasn't one already. I then read your comments and noticed that you'd recommended the same thing. I can delete my answer if you'd rather put yours. – Sonny Dec 20 '17 at 20:04
  • 1
    Like i said "Am I bovered" – RiggsFolly Dec 20 '17 at 20:07
  • @RiggsFolly - Thanks the amendment but that didn't actually solved the use of **limit** function in my sub query – Ritesh Aidasani Dec 20 '17 at 20:18
1

This skips the row with the lowest value of article_no:

SELECT *
    FROM article
    ORDER BY article_no ASC
    LIMIT 999999999
    OFFSET 1;

Perhaps you want DESC (instead of ASC) to skip the highest value?

Be aware that NOT IN ( SELECT ... ) is a very inefficient construct.

Rick James
  • 135,179
  • 13
  • 127
  • 222