Reputation: 353
I'm very new to SQL and was wondering if someone could direct me on how to obtain specific rows of data using the WHERE clause of an SQL file. This is my current WHERE clause:
CREATE or REPLACE view V_Status1
AS
SELECT
A.C0401_aid, B.C0401_description DESCR,
A.c0432_date DATEREQUIRED, A.C0432_sampl_value_r
FROM vhis_data A, T0401_accounts B
WHERE A.C0401_aid = B.C0401_aid
AND (B.C0401_aid = 5486 OR B.C0401_aid = 5489 OR B.C0401_aid = 5490);
5486, 5489 and 5490 represent the accounts that I need data from, but my current clause does not make sense for what I want. I need the data from all three accounts not just one. Please let me know if you need any clarification.
Upvotes: 0
Views: 81
Reputation: 3678
You can use the in
operator
example:
SELECT column_name(s)
FROM table_name
WHERE column_name IN (value1,value2,...);
Your case will looks like :
WHERE A.C0401_aid = B.C0401_aid AND
B.C0401_aid in(5486,5489,5490);
Upvotes: 2
Reputation: 3342
You are using the legacy JOIN
syntax. @TinyOS answer is correct, here is your original query in the more accepted current syntax:
CREATE or REPLAC view V_GTAAStatus1 AS
SELECT A.C0401_aid, B.C0401_description DESCR,
A.c0432_date DATEREQUIRED, A.C0432_sampl_value_r
FROM vhis_data A
INNER JOIN T0401_accounts B ON A.C0401_aid = B.C0401_aid
WHERE B.C0401_aid IN (5486, 5489, 5490);
Upvotes: 1
Reputation: 1155
Cleaned up the syntax, but this should perform the same operation your current query performs.
CREATE or REPLACE view V_GTAAStatus1 AS
SELECT A.C0401_aid,
B.C0401_description DESCR,
A.c0432_date DATEREQUIRED,
A.C0432_sampl_value_r [column_name]
FROM vhis_data A
LEFT JOIN T0401_accounts B on A.C0401_aid = B.C0401_aid
WHERE B.C0401_aid IN (5486,5489,5490);
Upvotes: 1