Showing entries 1181 to 1184
« 10 Newer Entries
Displaying posts with tag: sql (reset)
SQL to Select a random row from a database table

There are lots of ways to select a random record or row from a database table. Here are some example SQL statements that don't require additional application logic, but each database server requires different SQL syntax.

Select a random row with MySQL:

SELECT column FROM table
ORDER BY RAND()
LIMIT 1

Select a random row with PostgreSQL:

SELECT column FROM table
ORDER BY RANDOM()
LIMIT 1

Select a random row with Microsoft SQL Server:

SELECT TOP 1 column FROM table
ORDER BY NEWID()

Select a random row with IBM DB2

SELECT column FROM table
ORDER BY RAND() 
FETCH FIRST 1 ROWS ONLY

Thanks Tim

Select a random record with Oracle:

SELECT column FROM 
( SELECT column FROM table
  ORDER BY …
[Read more]
Nermalisation

An introduction to the normalisation of databases that requires no prior knowledge and serves as an excuse to introduce cat content into MySQL-dump.

Continue reading "Nermalisation"

A day in the docs

The most recent MySQL server I used in a production environment was a 3.23, so in conjunction with reading the 5.0 sources, I saw fit to reread large parts of the documentation to see where updates had happened, fixes were applied, extensions added. Here are some random clippings from the docs that illustrate quirks, changes from MySQL 3.23 (other than those noted in 3.23->4.0, 4.0->4.1, 4.1->5.0 which we'll give a brief tour of at the end) and differences from the standard. If you recently read the docs, kindly walk on, there's nothing to see here. If …

[Read more]
SQL-Zoo interactive tutorial

By chance, I came across this interactive interactive SQL tutorial — select your preferred engine, create queries for a variety of exercises, see the results online immediately. Instructive for the beginner, possibly fun for the advanced. : )

Showing entries 1181 to 1184
« 10 Newer Entries