SQL query to include one column value for one condition and exclude other columns
I am learning writing T-SQL queries can any help me writing the query for below scenario I have columns im.mfg with values(R, K, I ,Z) and orderfill with values(O,X,T) and my output should include columns im.mfg = k and od.orderfill = O, im.mfg values(R,K,I,Z) WHERE orderfill values(X,T) and exclude im.mfg values (R,I,T) where orderfill = O Select im.MFG,od.orderfill,im.ITEMID from ORDER od left join ITEMS im on im.ITEMID = od.ITEMID where od.orderfilled! = 'O'
You can make a WHERE clause as complicated as you need. It's a comination of one or more True/False expressions that control which rows come out. You can do things like: WHERE (ColumnA = 1 and ColumnB = 'X') OR (ColumnA = 2 and ColumnB != 'Y') So build up your WHERE clause one step at a time and test it as you go along.