This is rather simple - but I (vaguely :-) ) remember when I could barely
JOIN two tables - so I sympathise :-)
SELECT * FROM cars WHERE status = unsold AND (state = used OR state = new)
I presume that you are using the
; statement terminator?
SELECT * FROM cars WHERE status = unsold AND (state = used OR state = new);
But, that alone won't do the trick. In queries, for fields (
state) that are strings, you have to delimit (surround) them with single quotes, so your statement should look more like this:
SELECT * FROM cars WHERE status = 'unsold' AND (state = 'used' OR state = 'new');
On my profile, there are several articles on how to ask questions here - you might want to take a look?
Providing us with the table DDL (Data Definition Language) (i.e.
CREATE TABLE blah (...); (see below) would have been a big help here for example - always provide the maximum information possible - if in doubt, put it in!
For PostgreSQL, the command
\d table_name or
\d+ table_name would have been great. Even better would be, table structure(s), sample data (in the form of DML (Data Manipulation Language) -
INSERT INTO blah VALUES (....); - checkout the articles I mentioned.
For example, on my test database, I have a table called test_article, so to get its structure, I can do
pg_dump -t test_article -d test --schema-only
-t says it's the table
test-article I want,
-d says it's the database/schema test I want, and
--schema-only tells pg_dump that I only want the table structure and not data - this is what you'd want if you don't want any of the table's data - you could construct a sample table and use that - then remove the
--schema-only part of the bash command.
Output (important part):
CREATE TABLE public.test_article (
Information like this can be vital in helping us to solve your problems!
You can even run the
pg_dump command from within the psql PostgreSQL shell using the
\! psql command which invokes the bash shell - i.e.
test=# \! ./bin/pg_dump -t test_article -d test --schema-only;
Same result (and the best solution).
Take a look at a few SQL tutorial sites - pay attention to the ones specific to PostgreSQL, but my fave (and yours) database's SQL is by a long way the most compatible with the ANSII/ISO SQL standards - see here - in particular the Interoperability and Standardisation section.
p.s. welcome to the forum! :-)