harkly harkly - 1 month ago 4
MySQL Question

MySQL is duplicating results

Running a Select and it is duplicating the results 3 time for the 2nd WHERE clause, can someone help me out. I cannot find anything online to see if I can figure it out myself.

$searchCat = $mysqli->query("
SELECT
business.name, business.street
FROM
business, category
WHERE
(category.category_id = business.category_id AND category.name = '$searchTerm') OR
(business.search_term_8 = '$searchTerm')
")


It goes away when I use GROUP BY, if that is how it works great but I am concerned that it is not suppose to do that.

I definetly do not have any duplicate records in the table at this time.

Out put looks like this:


  • City Grill, 2841 E Sprague st - 5

  • Chappy's Restaurant, 13 Main St - 5

  • Chappy's Restaurant, 13 Main St - 5

  • Chappy's Restaurant, 13 Main St - 5

  • Howie's Pizza Bar, 552 Ace St - 5

  • Howie's Pizza Bar, 552 Ace St - 5

  • Howie's Pizza Bar, 552 Ace St - 5

  • House Inc, 123 - 5



Tables:

category


  • category_id :: 1, 2, 3

  • name :: bar, restaurant, spa



business


  • business_id :: 1, 2, 3, 4

  • business.name :: City Grill, Chappy's, Howie's; House Inc

  • business.street :: street info

  • category_id :: 1, ,1,1

  • search_term_1 :: empty

  • ---thru all are empty

  • search_term_8 :: bar



Searching for "bar"

Answer

Seems wrong where clause, try this:

$searchCat = $mysqli->query("
        SELECT 
            business.name, business.street
        FROM 
            business, category
        WHERE 
            category.category_id = business.category_id AND 
        (category.name = '$searchTerm' OR business.search_term_8 = '$searchTerm')
    ")