mysql - SQL query for multiple tag inclusion -


I'm very good at explaining this. But I try my best:

I have created a tagging tool for people. Some people have more than 1 tag, and I need to get them, but how to write SQL queries to include many tags.

I know that you can not write such conditions:
Lower (peoples_tags.tag_id) = 'Out' and
Lower (peoples_tags.tag_id) = 'Summer' < / P>

Because the result of each person is on its line and 'outside' and 'heat' will be used on the same line so you do not get any results using this query.

This is the full query:
Select from different people. * Tag people People Logos People People Tagged People on Tags Include tags on People.id - Tags tags. Tags = people_tag.tag_id and lower_times (peoples_tags.tag_id) = 'outside' and less (peoples_tags.tag_id) = 'summer'

How do I write a multiple tag SQL status? Anybody knows
Sorry for my bad english :)

You can call or < And instead of instead of your thinking process is: "I should get the lines where the keyword is 'outside', and rows where the keyword is 'summer' Code> AND ". But the way RDBMS looks at it, if you are keyword 'indoors' or keywords are 'summer' then you should return a given line ... so what you really need Or , not and .

Edit:

I think what you want to do now.

Try it out (maybe this is a more efficient / scalable way of doing it, but this should work)

  Select from local where it exists (from where people Select * People_tag.page_id = people. Id and species_tag.tag_id = 'out') and current (people from select * tags_ where people_tag.page_id = people. Id and public_tag.tag_id = 'summer')  

edit 2:

assuming that the combination of tag_ id and people_id is an uni for peoples_tags The key is the key, the following tasks will also be done:

  Select people *, COUNT (*) Contact people Join people people_id at people_id = people_tag.pool_polk where people_tag.tag_id = 'out' or 'people'tag TAG_ID = 'heat' group by people Getting co = 2  

Comments