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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:20:29+00:00 2026-05-23T03:20:29+00:00

I have problems to query my data. Here are my tables: CREATE TABLE `A`

  • 0

I have problems to query my data. Here are my tables:

CREATE TABLE `A` (
  `id` int(10) NOT NULL AUTO_INCREMENT,
  `myString` varchar(10) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1

CREATE TABLE `B` (
  `id` int(10) NOT NULL AUTO_INCREMENT,
  `myStringId1` int(10) NOT NULL,
  `myStringId2` int(10) NOT NULL,
  `value` varchar(10) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `index1` (`myStringId1`),
  KEY `index2` (`myStringId2`),
  CONSTRAINT `fk_B2` FOREIGN KEY (`myStringId2`) REFERENCES `A` (`id`),
  CONSTRAINT `fk_B1` FOREIGN KEY (`myStringId1`) REFERENCES `A` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1

where myStringId1 and myStringId2 have foreign key constraints to TABLE A (id)

Ok let me clarify what I want to achieve by query:
Lets assume some values for the given tables:

TABLE A:
ROW1: 22, "foo"
ROW2: 33, "bar"

TABLE B: 
ROW1: 1, 22, 33, "true"
ROW2: 2, 22, 22, "false"

Now what I need is a query where I give String “foo” and get the following result from joining the two tables:

RESULT:
ROW1: "foo","bar", "true"
ROW2: "foo", "foo", "false"

given String “bar” I expect this:

RESULT:
ROW1: “foo”,”bar”,”true”

any ideas ?

  • 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-23T03:20:30+00:00Added an answer on May 23, 2026 at 3:20 am

    After reading your comment I think this is closer to what you need:

    SELECT a1.myString as myString1, a2.myString as myString2, b.value
    FROM `B` b
        JOIN `A` a1 on a1.id = b.myStringId1
        JOIN `A` a2 on a2.id = b.myStringId2
    WHERE a1.myString = 'SOME STRING' OR a2.myString = 'SOME STRING'
    

    The two joins will ensure the both b.myStringId1 and b.myStringId2 are existing keys for TABLE A, and the WHERE ensures that one of those 2 strings is the one you need.

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

Sidebar

Related Questions

I initially create a table using some data loaded from a php mySQL query.
I seem to always have problems with converting data to and from XML in
I have a problem with an SQL query on Postgresql. This select clause is
I have a problem with the following Linq query using Entity Framework: from o
I have a problem that I would like have solved via a SQL query.
I seem to have a problem with this SQL query: SELECT * FROM appts
I have the following problem. If I query values with a keyfigure which is
I have the following query of linq to entities. The problem is that it
I have problems with bringing a windows mobile 6 form to the front. I
I frequently have problems dealing with DataRows returned from SqlDataAdapters . When I try

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.