Q:

MySQL query check two value in one column

I am writing one query where I have 4 types in column
Xtype
-----
P
C
D
R

I want to check where Xtype=P and Xtype=D so how can I use both for the same column? I know I can use for different column using WHERE id=1 AND status=online but not sure how to check two value for the same column

A:

You can use WHERE .. IN like this:
WHERE XType IN ('P','D')    -- checks whether the  Xtype is P or D

Which incidentally gets expanded into OR:
WHERE (XType = 'P' OR Xtype = 'D')

If you want to check whether that column contains records for both 'P' and 'D' then you could use a EXISTS & sub-query:
WHERE EXISTS (SELECT 1 FROM TableName WHERE Xtype = 'P') 
  AND EXISTS (SELECT 1 FROM TableName WHERE Xtype = 'D')

