dipika — 2011-06-26T13:41:39-04:00 — #1
I am developing a simple keyword search using php and mysql and I am facing problem while using "AND" and "PARENTHESIS" advanced search where user inputs the query. I developed following sql query:
Select * from Page LEFT JOIN Page_Tag LEFT JOIN Tag where((name="events" and name="news") or name="local")
I am not getting the answer of the "and" operation whereas "or" operation works properly.
And in parenthesis search, how do i parse input.
r937 — 2011-06-26T14:22:16-04:00 — #2
that's never going to be true, ever (and i think you know this already, right?)
the same column value cannot possibly be equal to two different things at the same time
you are going to have to re-think your strategy
jargonbust — 2011-06-26T15:37:55-04:00 — #3
try to make an inner join ad this might solve your problem
oddz — 2011-06-26T17:03:17-04:00 — #4
Looks like you want all the pages tagged either (events and news) or just local. Is that correct? Posting the create tables would help.
dipika — 2011-06-27T00:53:01-04:00 — #5
Yes, that is what I want.
oddz — 2011-06-27T01:46:08-04:00 — #6
From your query I can only grasp that there is a column named name inside the Page_Tag table which is just about worthless. The create tables are needed.
Edit: Besides that every row of the Page table is being joined on every row of the Page_Tag table, which I don't believe is what your after. I would assume where is something like page_id inside the table Page_Tag table that relates a tag to a page. If so please clearly define which column that is. Also it might be worth considering using a m:n relationship here rather then a 1:m relationship, unless there is a table called Tag somewhere just not part of the query.