Reputation: 312
I got a MySQL join problem I'm trying to figure for the past few hours. I have 2 tables:
article :
id(int)
label(varchar)
direct_url(varchar)
article_category:
id(int)
label(varchar)
I'm trying to make a search query using label and joining both tables. I'm doing this:
SELECT label,direct_url FROM article FULL OUTER JOIN article_category ON article.label WHERE label LIKE %$q% ORDER BY label ASC
This is obviously wrong because it doesn't work. I get 0 results every time regardless of the search key ($q). I would appreciate if somebody would shad some light into my problem.
Edit: my source is here.
Upvotes: 2
Views: 963
Reputation: 191749
MySQL does not support FULL OUTER JOIN
. What this does is actually alias the article
table to FULL
. There are two syntax errors: the OUTER JOIN
by itself, and missing quotes around the LIKE
value. JOIN ON article.label
is also not doing what you want it to do, most likely. It would have to be JOIN ON article.label = article_category.label
.
I'm pretty sure you don't want a full outer join -- conceptually this would be values in each table that are not in the other, but in fact it seems like you want to be able to search both label fields. If label
is the column that identifies the category, it would be better to use the article_category id instead of the current article.label
column. If that's not the case, then you don't have anything you can join the tables on anyway.
Upvotes: 2