background preloader

MySQL

Facebook Twitter

Build Date Generators and Manipulate Date and Time Data in SQL. Ometimes you need to generate sequences of date and/or time values.

Build Date Generators and Manipulate Date and Time Data in SQL

For example, take a data warehouse that has a multidimensional structure and stores the measures and dimensions in fact and dimension tables. Since one of the dimensions is almost always the time dimension, you would need to generate the sequence of date (time) values and load them into the time dimension table. This article demonstrates how to build date generators without the loops using SQL. In addition, it will show some useful techniques that can help you manipulate date and time data. Coding Horror: A Visual Explanation of SQL Joins. I love the concept, though, so let's see if we can make it work.

Coding Horror: A Visual Explanation of SQL Joins

Assume we have the following two tables. Table A is on the left, and Table B is on the right. We'll populate them with four records each. 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.

Common Queries Tree

CREATE TABLE packageCredit ( packageCreditID INT, packageCreditItemID INT, Interpreting Your Google Query. Understanding how Google treats your search terms will help you devise effective queries and revise ineffective ones. 1.

Interpreting Your Google Query

All Search Terms Count Google returns only pages that match all your search terms. A search for [ compact fold-up bicycle ] finds pages containing the words “compact” and “fold-up” and “bicycle.” Because you don't need to include the word AND between your terms, this notation is called an implicit AND. [ compact fold-up bicycle ] Because of implicit AND, you can focus your query by adding more terms. [ compact lightweight fold-up bicycle ] Note: If you want pages containing any (instead of all) of your search terms, use the OR operator. Note: Google sometimes returns pages that don't contain your query terms, as you can see in example. 2. Google returns pages that match your search terms exactly. Join (SQL) Da Wikipedia, l'enciclopedia libera.

Join (SQL)

Il JOIN è una clausola del linguaggio SQL che serve a combinare (unire) le tuple di due o più relazioni di un database tramite l'operazione di congiunzione (od unione) dell'algebra relazionale. Lo standard ANSI definisce alcune specifiche per il linguaggio SQL sul tipo di JOIN da effettuare: INNER, FULL, LEFT e RIGHT, alle quali diversi DBMS aggiungono CROSS. In alcuni casi è possibile che una tabella possa essere combinata con se stessa, in questo caso si parlerà di self-join. Learn SQL The Hard Way An Introduction To The Most Popular And Least Loved Data Language In The World.

Learn SQL The Hard Way Python | Ruby | C | Regex Learn SQL The Hard Way Table Of Contents Frequently Asked Questions.

Learn SQL The Hard Way An Introduction To The Most Popular And Least Loved Data Language In The World

LEFT JOIN / IS NULL vs. NOT IN vs. NOT EXISTS: nullable columns. In one of the previous articles I discussed performance of the three methods to implement an anti-join in MySQL.

LEFT JOIN / IS NULL vs. NOT IN vs. NOT EXISTS: nullable columns

Just a quick reminder: an anti-join is an operation that returns all records from one table which share a value of a certain column with no records from another table. In SQL, there are at least three methods to implement it: 1.SELECT o.* 2.FROM outer o 4. inner i. Less Than Dot - Wiki - 6 Different Ways To Get The Current Identity Value - Wiki. This tip will show you how to get the current identity value from a table and also some things that might act a little different than you would expect.

Less Than Dot - Wiki - 6 Different Ways To Get The Current Identity Value - Wiki

Let's first create our two simple tables CREATE TABLE TestOne (id INT identity,SomeDate DATETIME) CREATE TABLE TestTwo (id INT identity,TestOneID INT,SomeDate DATETIME) --Let's insert 4 rows into the table INSERT TestOne VALUES(GETDATE()) INSERT TestOne VALUES(GETDATE()) INSERT TestOne VALUES(GETDATE()) INSERT TestOne VALUES(GETDATE()) Here are 6 ways to check for the current value. SQL Injection Cheat Sheet. Find and exploit SQL Injections with free Netsparker SQL Injection Scanner SQL Injection Cheat Sheet, Document Version 1.4 About SQL Injection Cheat Sheet Currently only for MySQL and Microsoft SQL Server, some ORACLE and some PostgreSQL.

SQL Injection Cheat Sheet

Most of samples are not correct for every single situation. Most of the real world environments may change because of parenthesis, different code bases and unexpected, strange SQL sentences. Samples are provided to allow reader to get basic idea of a potential attack and almost every section includes a brief information about itself. SQL SERVER JOINs. Total votes: 1 Views: 369,729 Comments: 3 Category: SQL Print: Print Article Please login to rate or to leave a comment.

SQL SERVER JOINs

Published: 05 May 2009 By: Pinal Dave In this article, Author Pinal Dave clarifies the basic concepts of SQL JOINs. Introduction In this article, we’ll see the basic concepts of SQL JOINs. SQL Server Stored Procedures for Beginners. We are telling the database that we want to create a stored procedure that is called “usp_displayallusers” that is characterized by the code that follows. After the “AS” entry, you will simply enter SQL code as you would in a regularly query. For our first, we will use a SELECT statement: Now, your stored procedure should look like this:

SQL Subquery. Subquery or Inner query or Nested query is a query in a query. A subquery is usually added in the WHERE Clause of the sql statement. Most of the time, a subquery is used when you know how to search for a value using a SELECT statement, but do not know the exact value in the database. Subqueries are an alternate way of returning data from multiple tables. Subqueries can be used with the following sql statements along with the comparision operators like =, <, >, >=, <= etc.

SQL Tutorial - Dates. Date values are stored in date table columns in the form of a timestamp. A SQL timestamp is a record containing date/time data, such as the month, day, year, hour, and minutes/seconds. It's not much different from the standard date format. Visual Representation of SQL Joins. Introduction This is just a simple article visually explaining SQL JOINs. Background I'm a pretty visual person. Things seem to make more sense as a picture.

I looked all over the Internet for a good graphical representation of SQL JOINs, but I couldn't find any to my liking. Using the code I am going to discuss seven different ways you can return data from two relational tables. For the sake of this article, I'll refer to 5, 6, and 7 as LEFT EXCLUDING JOIN, RIGHT EXCLUDING JOIN, and OUTER EXCLUDING JOIN, respectively. What makes SQL slow. SQL performance problems are as old as SQL itself—some might even say that SQL is inherently slow. Although this might have been true in the early days of SQL, it is definitely not true anymore. Nevertheless SQL performance problems are still commonplace. How does this happen? The SQL language is perhaps the most successful fourth-generation programming language (4GL). Its main benefit is the capability to separate “what” and “how”.