mysql - Exclude from results if condition is met -


i have suppliers table many different suppliers in wanted show 1 particular supplier rather other if both present. there way compare results in select statement ?

something along lines of:

select  supplier, price  table  if in supplier (supplier1,supplier2)  select supplier   table  supplier <> supplier1 

is possible in mysql or better create array , way ?

thanks,

rick

edit @jim

at moment i'm selecting , results like:

supplier name | supplier price acme company | $12 acme company (northwest)    | $12 bobs company    | $13 craigs company  | $15 

acme company , acme company (northwest) same company, in cases both appear in results (they not) preference have acme companys price displayed.

if want 1 row returned, can fancy sort , select first result:

select supplier, price table  supplier in (supplier1, supplier2) order (case when supplier = 'supplier1' 1                when supplier = 'supplier2' 2           end) desc limit 1; 

this query order suppliers, based on conditions in case. because of desc keyword, 'supplier2' first , 'supplier1' second. limit chooses first row 'supplier2' if present , otherwise 'supplier1'.

edit:

if want eliminate 1 supplier if present do:

select supplier, price table t not (supplier = 'supplier1' ,            exists (select 1 table t2 t2.supplier = 'supplier2'           ); 

this return list has 1 supplier or other, not both.


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -