Click here to Skip to main content
15,885,196 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
+----------+------------+
| name     | code       |
+----------+------------+
| Fluffy   | 000        |
| Claws    | 217        |
| Buffy    | 598        |
| Fang     | 000        |
| Bowser   | 687        |
| Chirpy   | 587        |
| Whistler | 258        |
| Slim     | 298        |
| Fluffy   | 168        |
+----------+------------+


Here's my problem... in the above table the default value for column "code" is 000.In the column "name", Fluffy has 2 code one is the default 000 & the other one 168 When selecting, if fluffy has something other than the default code i've to select that & other rows leaving out the one row with default for Fluffy.Any way to do that with mysql IF or any other ? Hope my question is clear.
Posted
Updated 14-Nov-13 22:47pm
v2
Comments
GuyThiebaut 15-Nov-13 5:05am    
I don't understand what you are trying to do.
Can you give an example using data to illustrate what your expected result is - the example you give above only shows some of the data, I need to see more data and the result you expect to understand what you are wanting to do.
Thanks.

1 solution

That's actually really nasty! :laugh:
But it can be done.
I doubt if this is the most efficient way, but...
SQL
SELECT name, code FROM MyTable m 
WHERE code<>0 
   OR (SELECT COUNT(code) FROM MyTable t 
       WHERE m.name = t.name)=1
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900