Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Postgres Inner Join Select query returns error: column does not exist

Tags:

sql

postgresql

I have been reading through the documentation and I can't find what I'm doing wrong here.

I'm executing this query:

SELECT *
FROM "parts"
INNER JOIN "categories" ON "categories"."id" = "parts"."category_id"
WHERE "categories"."name" = "cars"

And I'm getting this error:

ERROR:  column "cars" does not exist
LINE 3: WHERE (categories.name = "cars")
                                 ^
********** Error **********

ERROR: column "cars" does not exist
SQL state: 42703
Character: 122

Category Table:

CREATE TABLE categories
(
  id serial NOT NULL,
  name character varying(255),
  CONSTRAINT categories_pkey PRIMARY KEY (id)
)

Parts Table:

CREATE TABLE parts
(
  id serial NOT NULL,
  category_id integer,
  CONSTRAINT parts_pkey PRIMARY KEY (id)
)

Any help would be greatly appreciated.

like image 896
newUserNameHere Avatar asked Feb 04 '14 19:02

newUserNameHere


1 Answers

You should use single apostrophes for string constants:

SELECT *
FROM "parts"
INNER JOIN "categories" ON "categories"."id" = "parts"."category_id"
WHERE "categories"."name" = 'cars'

The doubles mean db objects.(fields, tables, etc.)

(Otherwise they are not necessary, only for extras, for example spaces in names etc.)

like image 123
Lajos Veres Avatar answered Sep 20 '22 23:09

Lajos Veres