SQL Query returning to many results
Hello, I have a query where I am attempting to find records where a certain string appears in a given text field. For some reason, the below query returns multiple results when only a single record should be returned, and as part of the result set, it lists the same comment for every program. for some reason my
filter is not working.
WHERE programComments.comment LIKE '%earth%'
Any help is appreciated
SELECT programs.*, programComments.* FROM programs INNER JOIN programComments ON programComments.commentBy = programs.programManager WHERE programComments.comment LIKE '%earth%'
It's hard to be sure without understanding your data schema, but I suspect it's the nature of the inner join: you will get a result row for every matching join between the two tables (i.e.: every match for the ON clause). How to solve that will depend on exactly what you are trying to do and the actual data structure -- perhaps only selecting the exact fields you need (instead of "*") and using a DISTINCT would do the trick, but that's pure speculation at this point.
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)