Posts

Showing posts from 2012

Getting max record

Image
This short article was written for  group by and max usage.  If you need querying a table which items could have more than one values by max date, you can follow these steps. First of all lets look at our table : As you can see the table has more than one record for each id.  If you want get the values which have max date you should use following query and join. select id,MAX(date) dt from tabletest  group by id This query shows us records which have max date. select t1.* from tabletest t1 inner join ( select id,MAX(date) dt from tabletest group by id ) t2 on t1.id = t2.id and t1.date = t2.dt and this query shows us the values which have max date We used first query in the second query as a table and joined two tables via id and date columns.

sqlplus run a script

Image
When we work Oracle database with our fancy tools (like TOAD, SqlDeveloper), need to run some sql scripts. Toad, SqlDeveloper and other database tools have greate interface for doing these jobs but sometimes sql script can be too big for opening in a tool and running it. You face with memory problem when open too big sql script (200 MB). You can do it this job with sqlplus simple way. First of all you should open command line (in Windows). Command Window As you can see from the screenshot, you can connect database sqlplus "user/password@database" like this. user             : database user password   : database password database     : database which you want to connect. After successfully connected database you should see following screen. To run sql script we should write @{path}{file}. If we have a script in C drive, we should write (Windows): SQL> @C:\test.sql