Jump to content

multiple select mysql


funbinod
 Share

Recommended Posts

i'm trying to select columns with multiple conditions.

 

i want to select all 'tr_type' for all 'aid's but not 'SALES' & 'PURCHASE' for aid in '1' & '2'.

 

i tried ---

SELECT * FROM tran WHERE aid NOT IN ('1','2') AND tr_type IN ('SALES','PURCHASE') ORDER BY date

it didn't work. please suggest....

Link to comment
Share on other sites

SELECT * FROM tran WHERE NOT IN(SELECT aid FROM tran WHERE aid IN ('1','2') AND tr_type IN ('SALES','PURCHASE'))
Edited by birbal
Link to comment
Share on other sites

u r right but one---

i want all columns for all 'aid's but for 'aid' 1 & 2 i don't want 'sales' & 'purchase'. and 'sales' & 'purchase' are not column name. they are row value for 'tr_type' column & this column has other values also - 'receipt', 'payment' etc....

 

lets assume with this

|---|------------|--------|---------||aid|    date    |  amt   | tr_type ||---|------------|--------|---------|| 1 | 2014-05-01 | 50000  |  SALES  || 2 | 2014-05-02 | 50000  |PURCHASE ||---|------------|--------|---------|| 1 | 2014-05-03 | 50000  | RECEIPT || 2 | 2014-05-04 | 50000  | PAYMENT || 3 | 2014-05-05 | 50000  |  SALES  || 3 | 2014-05-06 | 50000  |PURCHASE ||---|------------|--------|---------|

in this table i dont want first 2 rows only.

Link to comment
Share on other sites

you can use union

SELECT * FROM tran WHERE aid IN('1','2') AND tr_type NOT IN ('SALES','PURCHASE'))UNIONSELECT * FROM tran WHERE aid NOT IN('1','2')
Edited by birbal
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...