Showing posts with label MySql Database. Show all posts
Showing posts with label MySql Database. Show all posts

Monday, January 19, 2015

How to select only duplicate records?

This is a guideline to select:

First ways:
 
Select State FROM Area
GROUP BY State
Having COUNT(*) > 1
 
Second ways:
 
 
SELECT DISTINCT a1.State
FROM AREA a1
JOIN AREA a2
  ON a1.AreaId != a2.AreaId  -- assume there is a Key to join on
  AND a1.State = a2.State    -- and such that different Areas with same State

Tuesday, August 19, 2014

Insert all values of a table into another table in SQL

The insert statement actually has a syntax for doing just that. It's a lot easier if you specify the column names rather than selecting "*" though:
 

INSERT INTO new_table (Foo, Bar, Fizz, Buzz) SELECT Foo, Bar, Fizz, Buzz FROM initial_table -- optionally WHERE ...

 
 
I'd better clarify this because for some reason this post is getting a few down-votes.
The INSERT INTO ... SELECT FROM syntax is for when the table you're inserting into ("new_table" in my example above) already exists. As others have said, the SELECT ... INTO syntax is for when you want to create the new table as part of the command.
You didn't specify whether the new table needs to be created as part of the command, so INSERT INTO ... SELECT FROM should be fine if your destination table already exists.

Thursday, January 24, 2013

Background of MySql Database

MySQL is a powerful and the most popular Open Source Software relational database management system
(RDBMS) that uses SQL (Structured Query Language). MySQL is officially pronounced "My esquel", not
"My sequel". It is popular for web applications. Previously, MySQL was developed, distributed, and
supported by MySQL AB now acquired by Sun Microsystems.
MySQL Development History

- MySQL was first released internally on 23 May 1995
- Windows version was released on January 8, 1998 for Windows 95 and NT
- Version 3.23: beta from June 2000, production release January 2001
- Version 4.0: beta from August 2002, production release March 2003
- Version 4.1: beta from June 2004, production release October 2004
- Version 5.0: beta from March 2005, production release October 2005
- Version 5.1: currently pre-production (since November 2005)
- Sun Microsystems acquires MySQL AB on 26 February 2008

MySQL Features History

- Version 3.23.23 Full-Text Search

- Version 4.0 Full-Text Search (IN BOOLEAN MODE), UNIONS

- Version 4.1 R-Tree and B-Tree, Sub-Queries, Prepared Statements

- Version 5.0 Cursors, Stored Procedures, Triggers, Views, XA Transactions

- Version 5.1 Event Scheduler, Partitioning, Plugin API, Row-Based Replication, Server Log Tables

To access MySQL databases several Libraries are available in all major programming languages. Beside
this, an ODBC interface named MyODBC allows additional programming languages that support the ODBC
interface to communicate with a MySQL database, such as Coldfusion or ASP. The MySQL server and its
official libraries are mostly implemented in ANSI C/ANSI C++. The MySQL Web site http://www.mysql.
com provides the latest information about MySQL.