Pull rows out, then filter them

INPUT · Slides

Conditions on text

01 / 04

Narrowing down by name

Not everything is a number or an id. Plenty of the time you want to narrow down by text — "the things we buy from Midori Stationery", say.

It goes in the same place, after WHERE. The only difference is how you write the value.

02 / 04

Text goes in '

A text value is wrapped in ' (single quotes). That is the SQL rule.

JavaScript let you use " or ', but the one that means text in SQL is '.

SELECT * FROM stocks  WHERE maker = 'Aoba Paper';

Result

2 | notebook | 200 | Aoba Paper | 25

03 / 04

Forget the quotes and it errors

Leave the quotes off and the word gets read as a column name. There is no such column, so back comes an error.

no such column: notebook is saying "there is no column called notebook". An error is telling you which bit it could not make sense of.

SELECT * FROM stocks  WHERE item = notebook;

Result

no such column: notebook

04 / 04

Numbers get no quotes

A number goes in as it is. Wrap it and it stops being a number and becomes text.

  • text … maker = 'Midori Stationery'
  • number … price = 120

Write it to match what is in the column. Let us try it.

SELECT item FROM stocks  WHERE maker = 'Midori Stationery';

Result

pencil
eraser
colour pencils