Page 1 of 1

Query Help

Posted: Thu May 31, 2007 11:55 am
by psurrena
Hello,

I'm having an odd problem. The query below is pulling from two tables. The table "category" has 11 records. When PHP displays the record in a loop, it will display "project_name" 11 times for each project. If I add another "category" record, it will display "project_name" 12 times. I only need / want each record to display once. Any help would be appreciated.

Code: Select all

SELECT project_id,project_name,category_full FROM project,category WHERE project_cat LIKE'%$cat%' ORDER BY project_name ASC

Posted: Thu May 31, 2007 12:03 pm
by superdezign
Which ones are repeating?

Maybe you should try some specificity.

Code: Select all

SELECT project.project_id, project.project_name, category.category_full
I don't know your table structure though, so this may not be the solution.

Posted: Thu May 31, 2007 1:20 pm
by feyd
Blind join will cause duplicates...

Re: Query Help

Posted: Sat Jun 02, 2007 7:38 pm
by califdon

Code: Select all

SELECT project_id,project_name,category_full FROM project,category WHERE project_cat LIKE'%$cat%' ORDER BY project_name ASC
You are asking for a JOIN between two tables, project and category, without specifying what the conditions for the join are. Either use LEFT JOIN ... ON ... syntax or set the criteria in the WHERE clause.

Posted: Mon Jun 04, 2007 7:39 am
by salmanshafiq
Dear,

You have not use any of the joing between both table therefore it's showing that records Use below query

SELECT P.project_id,P.project_name,C.category_full FROM project P,category C WHERE P.project_cat LIKE'%$cat%' AND P.categoryID=C.categoryID ORDER BY project_name
ASC


C.CategoryID will be the CategoryID in Category Table and P.CategoryID will be the categoryID used in project table

Posted: Mon Jun 04, 2007 11:03 am
by psurrena
With a few changes it worked great. Thank you so much!