Showing posts with label db. Show all posts

DB2 - SCHEMA - Query  

Posted by Kishore in

In DB2, normal select query like the one below, may not work properly

SELECT * FROM table;

In that cases, We need to specify the schema name to query the table.

SELECT * FROM schema.table;

Alternatively, for a query session, we can set the schema beforehand using,

SET SCHEMA schema_name;

Now this query will work fine :)

SELECT * FROM table;

Oracle SQL Limit  

Posted by Kishore in ,

Oracle SQL does not support anything like LIMIT in MySQL. You can just limit the
number of rows returned with rownum. So if you only want the first ten
records use:

SELECT * FROM table WHERE ROWNUM<10;>90 AND ROWNUM<100;

This is because Oracle checks for the first row and the condition is false,
as the rownum would be 1. So this row is not returned, thus the rownum is
still 0. So the rownum will never get to 90.

You can try :

SELECT * FROM table WHERE ROWNUM<101;
minus
SELECT * FROM table WHERE ROWNUM<91;

Alternate method:
select * from (select a, b, c, rownum as limit from mytable where conditions order by whatiwant) where limit>x and limit <y;

From http://www.weberdev.com/get_example-1445.html