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 8358715
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T10:53:23+00:00 2026-06-09T10:53:23+00:00

I’m using Mysql and I’m stuck on what I hope is a simple problem.

  • 0

I’m using Mysql and I’m stuck on what I hope is a simple problem.
I need to select data from a table if one condition is true or another condition is true.

One select I tried returns data, but a lot more data than it should. Indeed the table contains just 66 records however my query is returning 177 records. I’m misunderstanding something.

I need to select data if [‘city’ is equal to a value and ‘type’ is golden] or ‘type’ is within a category called ‘charms’

I’ve tried this query

SELECT b.* 
FROM bubbles b, bubble_types bt 
WHERE 
  b.city = 10 
  AND b.type = 'golden' 
  OR bt.category = 'charm' 
  AND bt.type = b.type;

and this one (which doesn’t work at all but may be closer to the mark?)

SELECT b.* 
IF(b.city = 10, b.type = 'golden'), 
IF(bt.category = 'charm', bt.type = b.type) 
FROM bubbles b, bubble_types bt;

Hopefully what I want makes sense?

I should get about 10 rows from the 66 of those bubbles in city 10 that are ‘golden’, or those bubbles whose type field puts them in category ‘charm’.

Thanks;

edit sample table data for bubble_types:

+----+----------+------------+ 
| id | category | type       | 
+----+----------+------------+ 
| 1  | bubble   | golden     | 
| 2  | charm    | teleport   | 
| 3  | charm    | blow       | 
| 4  | badge    | reuser     | 
| 5  | badge    | winner     | 
| 6  | badge    | loothunter | 
| 7  | charm    | freeze     | 
| 8  | badge    | reuser     | 
| 9  | badge    | winner     | 
| 10 | badge    | loothunter | 
+----+----------+------------+ 


mysql> describe bubbles;
+-------------+---------------------+------+-----+---------+----------------+
| Field       | Type                | Null | Key | Default | Extra          |
+-------------+---------------------+------+-----+---------+----------------+
| id          | bigint(20) unsigned | NO   | PRI | NULL    | auto_increment |
| city        | bigint(20)          | YES  |     | NULL    |                |
| type        | varchar(32)         | YES  |     | NULL    |                |
| taken_by    | bigint(20)          | YES  |     | NULL    |                |
| taken_time  | bigint(20)          | YES  |     | NULL    |                |
| label       | varchar(256)        | YES  |     | NULL    |                |
| description | varchar(16384)      | YES  |     | NULL    |                |
| created     | datetime            | YES  |     | NULL    |                |
+-------------+---------------------+------+-----+---------+----------------+
  • 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-06-09T10:53:24+00:00Added an answer on June 9, 2026 at 10:53 am

    You are so close! Take the “WHERE”-ness of your first go with the parenthesis of your second (and add an appropriate ON clause to your JOIN):

    SELECT b.* 
    FROM bubbles b
       JOIN bubble_types bt 
       ON b.type = bt.type
    WHERE 
      (b.city = 10 AND b.type = 'golden')
      OR 
      (bt.category = 'charm' AND bt.type = b.type);
    

    The devil is in the details of associativity of AND and OR in the where clauses. When in doubt, use parenthesis to make your intentions explicit.

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

Sidebar

Related Questions

I'm making a simple page using Google Maps API 3. My first. One marker
I am reading a book about Javascript and jQuery and using one of the
I am currently running into a problem where an element is coming back from
I have thousands of HTML files to process using Groovy/Java and I need to
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
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
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function

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.