Snippets! ;)

---
layout: article
title:  "Upsidedown pages with css"
date:   2015-07-07 20:37:06
categories: snippet
---

```
moz-transform: scale(-1,-1);
webkit-transform: scale(-1,-1);
transform: scale(-1,-1)
```

---
layout: article
title:  "SQL Cheatsheet"
date:   2015-07-07 20:37:06
categories: snippet
---

[SQL Run-through](https://www.youtube.com/watch?v=yPu6qV5byu4)

### Foreign Key Constraints
> Let's take our UNIQUE constraint a step further and ensure there are no duplicates for the combination of values within the name and language columns. To do that, we'll need to use a table constraint

```SQL
CREATE TABLE Movies (
  name varchar(50) NOT NULL,
  language varchar(50),
  CONSTRAINT name_lang UNIQUE (name,language)
);
```

>Indicate foreign key

```SQL
CREATE TABLE Actors (
  id int Primary Key,
  name varchar(50) Not Null Unique,
  country_id int references countries(id)
);

```

```SQL
CREATE TABLE Actors (
  id int PRIMARY KEY,
  name varchar(50) NOT NULL UNIQUE,
  country_id int,
  Foreign Key (country_id) REFERENCES Countries(id)
);
``

```SQL
CREATE TABLE Actors (
  id int PRIMARY KEY,
  name varchar(50) NOT NULL UNIQUE,
  salary integer CHECK (salary > 500),
  bonus integer CHECK (bonus < salary),
  country_id int REFERENCES Countries(id)
);
```





### Data Normalization
1. NF - Tables must not contain repeating groups of data in 1 column.
1. NF - Tables must not contain redundancy


#### Join Table
```SQL
CREATE TABLE Actors_Movies (
  actor_id int references actors(id),
  movie_id int references movies(id)
);
```

```

One-to-many:

  +--------+           +------------+
  | Movies |-----------| Promotions |
  +--------+ 1       * +------------+

Many-to-may:

 Movies ----------- Genre
        *          *

One-To-One

 Costumers ----------- Addresses
        1          1

```

```SQL
CREATE TABLE Rooms (
  id int PRIMARY KEY,
  seats int,
  movie_id int UnIQUE,
  FOREIGN KEY (movie_id) REFERENCES Movies(id)
);
```


```SQL
SELECT Movies.title,Rooms.id,Rooms.seats From Movies
JOIN Rooms
on Movies.id = Rooms.movie_id
where rooms.seats > 75
ORDER By rooms.seats DESC
;
```

```SQL
SELECT Actors.name,movies.title FROM Actors
INNER JOIN Actors_movies
on actors.id=actors_movies.actor_id
INNER JOIN Movies
on actors_movies.movie_id=movies.id
ORDER BY Movies.title
;
```

```SQL
SELECT A.name, M.title FROM Actors A
INNER JOIN Actors_Movies AM
ON A.id = AM.actor_id
INNER JOIN Movies M
ON AM.movie_id = M.id
ORDER BY M.title;
```


#### Outer Joins