background preloader

Common Queries Tree

Common Queries Tree
Common MySQL Queries Basic aggregation Last updated 05 Jan 2013 Aggregate across columns Last updated 09 Sep 2009 Aggregates across multiple joins Given a parent table and two child tables, a query which sums values in both child tables, grouping on a parent table column, returns sums that are exactly twice as large as they should be. CREATE TABLE packageCredit ( packageCreditID INT, packageCreditItemID INT, Last updated 22 Feb 2013 Aggregates excluding leaders You have a table of grouped ranks ... Last updated 21 May 2009 Aggregates of specified size Find the values of a table column c1 for which there are a specified number of listed values in another column c2. All X for which all Y are Z You have an election database with tables for candidates, parties and districts. CREATE TABLE districts ( district char(10) DEFAULT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1; INSERT INTO districts VALUES ('Essex'),('Malton'),('Riverdale'),('Guelph'),('Halton'); Avoiding repeat aggregation Cascading aggregates

SQL Buddy - Web based MySQL administration SQL Fool Self-Professed SQL Scripting Junkie! MySQL Cookbook, Second Edition Welcome to the Web site for MySQL Cookbook, Second Edition. The book covers techniques for solving many different SQL problems, and how to write your own MySQL programs using Perl, Ruby, PHP, Python, and Java. It is written in problem-and-solution format to make it easy for you to find the answers to your questions. It contains SQL-only recipes, command line scripts, and web scripts (using Apache for Perl, Ruby, PHP, and Python; and Tomcat for Java and JSP/JSTL). The second edition brings the recipes up to date for MySQL 5.0/5.1. Read this page in Romanian translation (by Web Geek Science). Inquiries may be sent to mysql-cookbook@kitebird.com. How to: Create a Trace (Transact-SQL) This topic describes how to use stored procedures to create a trace. To create a trace Execute sp_trace_create with the required parameters to create a new trace. The following code demonstrates creating a trace using Transact-SQL. The following code creates a trace, adds events to the trace, and then starts the trace: DECLARE @RC int, @TraceID int, @on BIT EXEC @rc = sp_trace_create @TraceID output, 0, N'C:\SampleTrace' -- Select the return code to see if the trace creation was successful. Now that the trace has been created and started, execute the following code to populate the trace with activity. SELECT * FROM master.sys.databases GO SELECT * FROM ::fn_trace_getinfo(default) GO The trace can be stopped and restarted at any time. DECLARE @TraceID int -- Populate a variable with the trace_id of the current trace SELECT @TraceID = TraceID FROM ::fn_trace_getinfo(default) WHERE VALUE = N'C:\SampleTrace.trc' -- First stop the trace.

SQL Syntax The SQL query strings for Windows Installer are restricted to the following formats. SQL Grammar The optional parameters are shown enclosed in brackets [ ]. When several choices are listed, the optional parameters are separated by a vertical bar. A {constant} is either a string or an integer. A string must be enclosed in single quote marks 'example'. The LOCALIZABLE option sets a column attribute that indicates the column needs to be localized. A {column} is a columnar reference to a value in a field of a table. A WHERE {operation-list} clause is optional and is a grouping of operations to be used to filter the selection. {column} = {column}{column} = | <> | > | < | >= | <= {constant}{column} = | <> | > | < | >= | <= {marker}{column} is null{column} is not null For string values, only the = or <> operations are possible. Individual operations can be grouped by AND or OR operators. The ORDER BY clause is optional and causes an initial delay during sorting.

SQL Tutorial - Learn SQL SQL is short for Structured Query Language and is a widely used database language, providing means of data manipulation (store, retrieve, update, delete) and database creation. If you need a quick SQL reference, make sure you download or PDF SQL Cheat Sheet. Almost all modern Relational Database Management Systems like MS SQL Server, Microsoft Access, MSDE, Oracle, DB2, Sybase, MySQL, Postgres and Informix use SQL as standard database language. Our SQL tutorial will teach you how to use commonly used SQL commands and you will be able to apply most of the knowledge gathered from this SQL tutorial to any of the databases above. . SQL Tutorial Table of Contents SQL Tutorial This chapter explains what SQL (Structured Query Language) is, and where and how it is used. SQL Table SQL Database Tables are the building blocks of every RDBMS (Relational Database Management System). SQL SELECT INTO Learn how to use the SQL SELECT INTO statement to copy data between database tables.

Using Oracle PL-SQL Resources Database Systems: The Complete Book by Hector Garcia, Jeff Ullman, and Jennifer Widom. A First Course in Database Systems by Jeff Ullman and Jennifer Widom. Gradiance SQL Tutorial. Note: The material on triggers that was formerly in this document has been moved to A New Document on Constraints and Triggers. Basic Structure of PL/SQL PL/SQL stands for Procedural Language/SQL. DECLARE /* Declarative section: variables, types, and local subprograms. */ BEGIN /* Executable section: procedural and SQL statements go here. */ /* This is the only section of the block that is required. */ EXCEPTION /* Exception handling section: error handling statements go here. */ END; Only the executable section is required. To execute a PL/SQL program, we must follow the program text itself by Variables and Types Information is transmitted between a PL/SQL program and the database through variables. DECLARE price NUMBER; myBeer VARCHAR(20); Types in PL/SQL can be tricky. DECLARE myBeer Beers.name%TYPE;

Related: