Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 986331
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T05:18:12+00:00 2026-05-16T05:18:12+00:00

What I’d like to do is search in a table with two different values,

  • 0

What I’d like to do is search in a table with two different values, it’s hard to explain so I will just give an example.

Table: people

+----------------+
| id     name    |
|----------------|
| 1      Bob     |
| 2      Jack    |
| 3      Waly    |
| 4      Alex    |
++++++++++++++++++

Table: animals

+------------------------------------------+
| id   person    key          value        |
|------------------------------------------|
| 1    1         dog          Terrier      |
| 2    1         dog          Shepherd     |
| 3    1         bird         African Grey |
| 4    3         cat          Toyger       |
| 5    3         cat          Korat        |
| 6    2         dog          Terrier      |
++++++++++++++++++++++++++++++++++++++++++++

For example: I would like to be able to select just the people that have a dog that is a Terrier and a African bird so it should return 1 (Bob). I need to be able to add and remove parameters I may just want people who have a Terrier dog should return 1 (Bob) and 2 (Jack).

I have tried basic sql but have gotten it to work because when you limit the key you can search another one. The following query is what I have tried and I want to return: 1 (Bob).

SELECT p.id, p.name
FROM people p, animals a
WHERE p.id = a.person
AND (a.key = 'dog' AND a.value LIKE '%Terrier%' )
AND (a.key = 'bird' AND a.value LIKE '%African%' )

If at all possible I would like to keep all of the animals rows in the same table so I don’t have to separate them out. Thanks for all of your help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T05:18:12+00:00Added an answer on May 16, 2026 at 5:18 am

    You’ll need multiple table lookups, each searching for a particular animal. For example, using a double join:

    select  *
    from    people p
    join    animals a1
    on      a1.person = p.id
    join    animals a2
    on      a2.person = p.id
    where   a1.key = 'dog' and a1.value like '%Terrier%'
            and a2.key = 'bird' and a2.value like '%African%'
    

    Or a double exists:

    select  *
    from    people p
    where   exists
            (
            select  *
            from    animals a
            where   a.person = p.id
                    and a.key = 'dog' 
                    and a.value like '%Terrier%'
            )
            and exists
            (
            select  *
            from    animals a
            where   a.person = p.id
                    and a.key = 'bird' 
                    and a.value like '%African%'
            )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables with like below codes: Table: Accounts id | username |
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I've got a string that has curly quotes in it. I'd like to replace
I would like to run a str_replace or preg_replace which looks for certain words
I am trying to render a haml file in a javascript response like so:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.