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

  • Home
  • SEARCH
  • 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 7094159
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T08:31:43+00:00 2026-05-28T08:31:43+00:00

Having trouble getting this syntax right: SELECT DISTINCT id FROM metadata WHERE (meta_key =

  • 0

Having trouble getting this syntax right:

SELECT DISTINCT id 
FROM metadata 
WHERE (meta_key = 'school' AND meta_value = 'Some School') 
AND WHERE (meta_key = 'hidden' AND meta_value = '1')

Its failing at line 4…

UPDATED:
Table looks like this:

meta_id - id - meta_key     - meta_value
1         1    school         Some School 1
2         1    hidden         0
3         2    school         Some School 2
4         2    hidden         1
5         3    school         Some School 3
6         3    hidden         0
7         4    school         Some School 4
8         4    hidden         0
9         5    school         Some School 5
10        5    hidden         1

UPDATED: I have a related, extended here Does row exist and multiple where

  • 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-28T08:31:44+00:00Added an answer on May 28, 2026 at 8:31 am

    You do not need a second where, and the second and was probably intended to be an or:

    SELECT DISTINCT id 
    FROM metadata 
    WHERE (meta_key = 'school' AND meta_value = 'Some School') 
    OR (meta_key = 'hidden' AND meta_value = '1')
    

    (the reason I think you wanted an or is because otherwise you have a conjunction of contradictory clauses meta_key = 'school' AND meta_key = 'hidden', which is always false).

    EDIT : In response to OP’s comment about the results he is trying to get, here is a different query:

    SELECT DISTINCT m1.id 
    FROM metadata m1
    join metadata m2 on m1.id = m2.id
    WHERE (m1.meta_key = 'school' AND m1.meta_value = 'Some School') 
    AND (m2.meta_key = 'hidden' AND m2.meta_value = '1')
    

    Now the conjunction clauses are no longer contradictory, because they refer to two different rows m1 and m2.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having some trouble getting log4net to work from ASP.NET 3.5. This is the
I am having trouble getting the right syntax for this. Say I have two
I'm having trouble getting any information to display from this query. Anyone know where
This is probably stupid simple, but for some reason I'm having trouble getting it
I'm having trouble getting a sample program to link correctly (in this case against
I'm having trouble getting the right number of elements in the ArrayList alt in
Having trouble getting this to work. What's strange is that I have 10 bookmarks
I'm having trouble getting this to work...it just replaces the entire page with the
I am having trouble getting this to work so any help would be appreciated!
I am having trouble getting this to work. I have variables initiated in main

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.