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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:19:52+00:00 2026-05-27T10:19:52+00:00

I have the following table structure: CREATE TABLE a ( a_id int(10) unsigned NOT

  • 0

I have the following table structure:

CREATE TABLE a (
 a_id int(10) unsigned NOT NULL AUTO_INCREMENT,
);

CREATE TABLE b {
 b_id int(10) unsigned NOT NULL AUTO_INCREMENT,
};

CREATE TABLE cross (
 a_id int(10) unsigned NOT NULL,
 b_id int(10) unsigned NOT NULL,
 PRIMARY KEY (a_id),
 KEY (b_id),
 CONSTRAINT FOREIGN KEY (a_id) REFERENCES a (a_id),
 CONSTRAINT FOREIGN KEY (b_id) REFERENCES b (b_id)
);

CREATE TABLE prices (
 a_id int(10) unsigned NOT NULL,
 price int(10) NOT NULL,
 PRIMARY KEY (a_id),
 CONSTRAINT FOREIGN KEY (a_id) REFERENCES a (a_id)
);

I would like to retrieve every b_id value for which there are inconsistent prices. A b.id value ‘B’ has an inconsistent price if the following conditions both hold:

  1. There exist two a_id values (say, ‘A1’ and ‘A2’) such that table cross contains both (‘A1’, ‘B’) and (‘A2’, ‘B’). (For any b_id value, there may be zero or more rows in cross.)
  2. Either ‘A1’ and ‘A2’ correspond to rows of prices that have different values of price, or else exactly one of ‘A1’ and ‘A2’ corresponds to an entry in prices.

Because of restrictions by the hosting provider, I cannot use stored procedures with this data base. I haven’t figured out a sensible way to do this with SQL queries. So far, I’ve resorted to retrieving all relevant data and scanning for inconsistencies in Perl. That’s a lot of data retrieval. Is there a better way? (I’m using InnoDB, if it makes a difference.)

  • 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-27T10:19:53+00:00Added an answer on May 27, 2026 at 10:19 am
    /* Condition 1 and Condition 2a */ 
    SELECT 
        c.b_id
    FROM
        `cross` AS c
        JOIN prices AS p ON (p.a_id = c.a_id)
    GROUP BY
        c.b_id
    HAVING
        COUNT(c.a_id) > 1 AND
        MAX(p.price) != MIN(p.price)
    
    UNION
    
    /* Condition 1 and Condition 2b */
    SELECT 
        c.b_id
    FROM
        `cross` AS c
        LEFT JOIN prices AS p ON (p.a_id = c.a_id)
    GROUP BY
        c.b_id
    HAVING
        COUNT(c.a_id) > 1 AND
        SUM(IF(p.price IS NULL, 0 ,1)) = 1;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following table structure CREATE TABLE `table` ( `id` int(11) NOT NULL
Lets say I have the following MySQL structure: CREATE TABLE `domains` ( `id` INT(10)
I have following table structure: Table: Plant PlantID: Primary Key PlantName: String Table: Party
I have the following table structure in my database: create table Encargado( ID int
I have the following structure SET SQL_MODE=NO_AUTO_VALUE_ON_ZERO; CREATE TABLE IF NOT EXISTS `sis_param_tax` (
I have a table with the following structure: CREATE TABLE `game_entries` ( `id` int(11)
I have following table structure: CREATE TABLE pilot_groups ( id INT PK, name VARCHAR(50),
I have the following data structure and data: CREATE TABLE `parent` ( `id` int(11)
I have a table with following structure : id, - Primary key minlatitude -
I have created a table with the following structure- $sql = CREATE TABLE followers

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.