Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You have three choices.</p> <p>The first is to go down the path you are one and try to compare two comma delimited lists. This produces really, really ugly SQL. It does not allow indexes. The basic idea is something like:</p> <pre><code>where find_in_set(substring_index(@list, ',', 1), CarBrands) &gt; 0 or find_in_set(substring_index(substring_index(@list, ',', 2), ',', -1), CarBrands) &gt; 0 or . . . </code></pre> <p>The second is to introduce a new table, which has one row for a user and a favorite whatever. Let's make this general, so there is a column for the user, a column for category ("CarBrand") and a name. Then the query looks something like:</p> <pre><code>from Profile p left outer join Favorites f on p.userId = f.userId and f.Category = 'CarBrand' group by p.userId having sum(f.Name = 'Mercedes') &gt; 0 and sum(f.Name = 'BMW') &gt; 0; </code></pre> <p>The third option is to use full text search and the <code>match</code> function. The documentation is <a href="http://dev.mysql.com/doc/refman/5.5/en/fulltext-boolean.html" rel="nofollow">here</a>.</p> <p>My guess is that a full text index is probably the easiest way for you to do what you want.</p> <p>EDIT:</p> <p>The query about full text index versus option 2. Probably the key question has to do with stop words and short terms. The full text index, for instance, drops words with less than 4 characters (by default, you can change both of these). It also has a list of stop words.</p> <p>My personal inclination would be to use the second option. But the reasons may not be good ones. It uses standard SQL and I'm comfortable with the data structures and queries. So, it gives me more control over the results.</p> <p>In your case, the full text search is probably easier to implement quickly and would very likely be as fast or faster. The full text search also lets you do more complex booleans, such as mixing "AND" and "OR" and doing natural language search to get a relevance value.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload