sql

How to reverse a MySQL result set?

Feb
04

I need to grab last 100 rows of a MySQL table, and loop them through in reverse order. The array_reverse() PHP function won't reverse the "resource" or "array" data types, so it isn't as easy to reverse the array of "mixed" data type. The best way to achieve this is by using a SQL statement as shown below.

SELECT * FROM (SELECT * FROM mytable ORDER BY id DESC limit 100) 
AS foo ORDER BY id ASC;

You may also retrieve the MySQL result set in descending order, and traverse the set in reverse order.

Posted By admin read more

Getting Started with Oracle SQL*Plus

Feb
04

SQL*Plus is a command-line application that allows you to manage virtually every facet of the Oracle database. This article may be viewed as FAQs on SQL*Plus.

Before using SQL*Plus, there are a number of environment setting that you may want to configure. To toggle any of those settings, use the SET command shown below.

% sqlplus username
Enter Password: *****
SQL> SHOW ALL
SQL> SET {setting} ON/OFF

To turn on SQL query results to the terminal, set the following environment variable.

Posted By admin read more

Oracle Import and Export: how to use it?

Feb
04

The Oracle export (exp) and import (imp) utilities are used to perform logical database backup and recovery, which allow you to write data into an operating system file and read back into the Oracle database. They are also used to move Oracle schema and data from one machine to another, or one database to another.

The exp/imp utilities use an Oracle proprietary binary file format and can thus only be used between Oracle databases. One cannot export data and expect to import it into a non-Oracle database.

Posted By admin read more

T-SQL Command Reference

Feb
04

Local Variable Declaration

DECLARE @X  INT
DECLARE @A INT, @B INT, @C CHAR(10)

A local variable is initially assigned a NULL value. A value can be assigned to a local variable by using the SET or SELECT statement.

DECLARE @X INT
SET @X = 1
SELECT @X = COUNT(*) FROM db.dbo.books

IF ... ELSE statement

Posted By admin read more

Pages

Subscribe to RSS - sql