views:

20

answers:

1

Hi, I've used this MySQL query to get data:

SELECT DISTINCT A.*, B.username
FROM posts A, members B
WHERE B.status=1
AND (A.USERID=B.USERID AND A.title LIKE '%myquery%' AND B.public='1' AND A.type = 'update' )
order by A.ID desc limit 0, 10

this works to search title row, but i need to search into title and msg row, how to "merge" (?) these two rows into one and make my query?

this is my basic schema.

----------------------------
ID |  title  | msg ...     |
----------------------------
 1 | example | hello there |  example data.

PS. sorry for my english.

+1  A: 

if i understand your question

you can use the OR

... AND (A.title LIKE '%myquery%' OR A.msg LIKE '%myquery%') ...
Haim Evgi
don't works, cause i got repetead ID's,i need unique ID's,
greenbandit
you can use DISTINCT(A.id) , ITS NOT help ? what you get exactly ?
Haim Evgi
not work, any idea?the query is for a search box, original query to search in titles, original but change A.title for A.msg to seearch in msg. what am looking for is a way to search in all "post" (title+msg) and show has unique result.
greenbandit
CAN YOU SHOW THE RESULT with the OR ANSWER ?
Haim Evgi
did you run this ? SELECT DISTINCT A.*, B.usernameFROM posts A, members BWHERE B.status=1AND (A.USERID=B.USERID AND (A.title LIKE '%myquery%' OR A.msg LIKE '%myquery%' ) AND B.public='1' AND A.type = 'update' )order by A.ID desc limit 0, 10
Haim Evgi
thanks, now works good...
greenbandit