Lewis Day Lewis Day - 6 months ago 17
SQL Question

Using WHERE clause twice on same column?

I'm trying to select twice from the same column I read a few previously posted questions and some people where suggesting using

T1.
and
T2.
however I'm unsure on how to implement these into this example. So what I'm trying to do is select twice from the
statement_type
column. WHERE the value is either
WTHD
OR
TIP


SELECT * FROM `usr_statements`
WHERE `username` = '$username' AND `statement_type` = 'WTHD' AND `statement_type` = 'TIP'
ORDER BY `statement_ref`";


The column I'm trying to sort from twice is the
statement_type
.

WHERE `username` = '$username' AND `statement_type` = 'WTHD' AND statement_type` = 'TIP'

Answer

You can either use OR:

WHERE `username` = '$username' AND (`statement_type` = 'WTHD' OR `statement_type` = 'TIP')

or use IN

WHERE `username` = '$username' AND `statement_type` IN('WTHD', 'TIP')