newbie here. Apologies in advance if I don't use the proper terminology.
SITUATION: I'm working with my first SQL database, and the cells in one column have multiple values, many of which overlap with other cells. Here's an excerpt (I'm new to stack overflow and can't insert images yet, and I can't figure out the best way to represent the layout in text, but here's my best attempt):
aardvark | animal mammal carnivore
tiger | animal carnivore mammal
snail | animal mollusk
QUESTION: How do I call all rows that have a combination of specific multiple values, but not necessarily in the order queried?
EXAMPLE OF the DESIRED OUTCOME: Using the columns/values listed above, I want to pull only rows that have BOTH 'animal' and 'mammal' values in column 2 (so row_1 and row_2, but not row_3).
EXAMPLES OF FAILED/CONFUSING ATTEMPTS (using the columns/values listed above):
- if I do:
SELECT * FROM
table_nameWHERE col_name LIKE '%mammal%' AND '%animal%'
, zero rows are returned (which happens regardless of whether '%mammal%' or '%animal%' is listed first) - if I do
SELECT * FROM
table_nameWHERE col_name LIKE '%animal%' OR '%mammal%'
, all three rows are returned (which I expected to happen, but...) - if I switch the LIKE conditions while using OR (
SELECT * FROM
table_nameWHERE col_name LIKE '%mammal%' OR '%animal%'
), only rows 1 and 2 are returned
Does SQL support this kind of query? I've spent the past couple of days searching for a solution, and the closest I got was I think ALL might have something to do with it, but if that is the case I haven't been able to figure out the right syntax. I've looked around and found some articles about how to combine multiple column values into one cell, but not how to search for them. I considered reformatting the table so the column has only one value per cell, but that would require adding a bunch more columns to accommodate all of the values, and it seems like that would make searching a lot more complicated because it would require searching all of those columns instead of just one.
Thanks!