Skip to content

hchiam/learning-sql

Repository files navigation

Learning SQL

Just one of the things I'm learning. https://github.com/hchiam/learning

Older tutorials

Node.js MySQL tutorial

Miscellaneous notes

Here's an alternative diagram to using venn diagrams to understand SQL joins: https://www.reddit.com/r/SQL/comments/1bv88ht/please_use_these_instead_of_those_abominable_venn/

UDF (user-defined function):

temporary UDF:

CREATE TEMP FUNCTION AddFourAndDivideTemporary(x INT64, y INT64)
RETURNS FLOAT64
AS (
  (x + 4) / y
);

SELECT
  val, AddFourAndDivideTemporary(val, 2)
FROM
  UNNEST([2,3,5,8]) AS val;

persistent UDF: (requires a dataset like "mydataset." specified for the function)

CREATE FUNCTION mydataset.AddFourAndDividePersistent(x INT64, y INT64)
RETURNS FLOAT64
AS (
  (x + 4) / y
);

SELECT
  val, mydataset.AddFourAndDividePersistent(val, 2)
FROM
  UNNEST([2,3,5,8,12]) AS val;

https://dba.stackexchange.com/questions/283022/what-does-the-go-statement-do-in-sql-server

  • GO = end of scope = came from telling CLI that it can now send the server the batch of multiline SQL code
  • ; separates lines in a batch and does not separate scope

https://www.w3schools.com/sql/sql_delete.asp

  • DELETE FROM table_name WHERE condition; --OK
  • DELETE FROM table_name; --likely BAD: will delete entire table

About

Learning SQL

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published