MySQL Forums
Forum List  »  Newbie

Selecting specified values from different coulmns
Posted by: shreehari srinivasan
Date: October 07, 2022 09:03AM

I'm a student and I'm new to MySQL, I recently came across a question that asked me to create a view of games with word 'ball' in them from 2 columns namely game1 and game2. I tried it in a way, but as I'm selecting both columns, if a column's value contains a match, it is displaying both values of column game1 as well as game2.

tabel: sports
game1 | game2
swimming | football
athletics | tennis
basketball | cricket

Querry I tried :
-> select game1,game2 from sports
-> where game1 like '%ball%' or game2 like '%ball%';

Output I got :
+------------+----------+
| game1 | game2 |
+------------+----------+
| swimming | football |
| basketball | cricket |
+------------+----------+

Output I need :
+------------+----------+
| game1 | game2 |
+------------+----------+
| basketball | football |
+------------+----------+

Please let me know if there is a query That i can use to get the result as needed

I'm new to this forum, so I'm not sure how I could attach screenshots :(

Options: ReplyQuote


Subject
Written By
Posted
Selecting specified values from different coulmns
October 07, 2022 09:03AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.