Jump to content

Adding a where clause to query


Go to solution Solved by gizmola,

Recommended Posts

 

Hi. How would i go about adding a WHERE clause to this query...

SELECT *, l.link_id
          , l.url
          , l.title
          , t.term
          , d.content
          , d.link_id
          , SUM(MATCH(t.term) AGAINST('w00t' IN BOOLEAN MODE) + MATCH(url, title) AGAINST('w00t') + MATCH(d.content) AGAINST('w00t'))  as `rank`
     FROM links l
          JOIN terms t ON l.link_id = t.link_id
          JOIN links_description d ON d.link_id = l.link_id

     WHERE MATCH(t.term) AGAINST('w00t' IN BOOLEAN MODE)
           OR MATCH(url, title) AGAINST('w00t')    
           OR MATCH(content) AGAINST('w00t')
     GROUP BY title
     ORDER BY `rank` DESC LIMIT 200;

Ive tried the following, but it doesn't work, 
 

SELECT *, l.link_id
          , l.url
          , l.title
          , t.term
          , l.content_type
          , d.content
          , d.link_id
          , SUM(MATCH(t.term) AGAINST('w00t' IN BOOLEAN MODE) + MATCH(url, title) AGAINST('w00t') + MATCH(d.content) AGAINST('w00t'))  as `rank`
     FROM links l
          JOIN terms t ON l.link_id = t.link_id
          JOIN links_description d ON d.link_id = l.link_id

     WHERE MATCH(t.term) AGAINST('w00t' IN BOOLEAN MODE)
           OR MATCH(url, title) AGAINST('w00t')    
           OR MATCH(content) AGAINST('w00t')
     AND   MATCH(l.content_type) AGAINST('docume') // <-----------------------
     GROUP BY title
     ORDER BY `rank` DESC LIMIT 200;

Does not filter the results at all, based on content_type.

Edited by oz11
Link to comment
https://forums.phpfreaks.com/topic/317703-adding-a-where-clause-to-query/
Share on other sites

  • Solution

It also looks like you want to group the prior fulltext searches, so something like this?

 

SELECT *, l.link_id
          , l.url
          , l.title
          , t.term
          , l.content_type
          , d.content
          , d.link_id
          , SUM(MATCH(t.term) AGAINST('w00t' IN BOOLEAN MODE) + MATCH(url, title) AGAINST('w00t') + MATCH(d.content) AGAINST('w00t'))  as `rank`
     FROM links l
          JOIN terms t ON l.link_id = t.link_id
          JOIN links_description d ON d.link_id = l.link_id

     WHERE (MATCH(t.term) AGAINST('w00t' IN BOOLEAN MODE)
           OR MATCH(url, title) AGAINST('w00t')    
           OR MATCH(content) AGAINST('w00t'))
     	   AND l.content_type = 'docume')
     GROUP BY title
     ORDER BY `rank` DESC LIMIT 200;

 

 

 

 

  • Great Answer 1

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.