SELECT Statements in PostgreSQL - Examples
SELECT using WHERE:
Consider the table user_table
with the following structure:
CREATE TABLE sch_test.user_table
(
id serial NOT NULL,
username CHARACTER VARYING,
pass CHARACTER VARYING,
first_name CHARACTER varying(30),
last_name CHARACTER varying(30),
CONSTRAINT user_table_pkey PRIMARY KEY (id)
);
Syntax:
SELECT * FROM schema_name.table_name WHERE <condition>;
SELECT field1, field2 FROM schema_name.table_name WHERE <condition>;
Examples:
Select everything where id
is 1:
SELECT * FROM sch_test.user_table WHERE id = 1;
Select id
where username
is 'root' and pass
is 'toor':
SELECT id FROM sch_test.user_table WHERE username = 'root' AND pass = 'toor';
Select first_name
where id
is not equal to 1:
SELECT first_name FROM sch_test.user_table WHERE id != 1;