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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T22:52:00+00:00 2026-06-10T22:52:00+00:00

I’ve the following three tables: Table A: id VARCHAR(32) | value VARCHAR(32) | groupId

  • 0

I’ve the following three tables:

Table A:

id VARCHAR(32) | value VARCHAR(32) | groupId INT
abcdef         | myValue1          | 1
ghijkl         | myValue2          | 2
mnopqr         | myValue3          | 1

Table B:

id VARCHAR(32) | value VARCHAR(32) | userId INT
abcdef         | myValue4          | 1
uvwxyz         | anotherValue      | 1

Table C:

id VARCHAR(32) | someOtherColumns...
abcdef
ghijkl
mnopqr
...
uvwxyz

Table A and B are used for a m:n-association, thus the “id”-column in both tables references the same field (“id”-column in table c).
What I want to do is (for instance)… select all entries in table A where groupId = 1

SELECT * FROM TableA WHERE groupId = 1

and also select all entries in table B where userId = 1

SELECT * FROM TableB WHERE userId = 1

That’s all no problem… but the following makes the select-statement(s) difficult: How can I merge both select-results and replace the value of the first result? For example:

selecting all entries in Table A where groupId = 1 I’ll get abcdef and also mnopqr.
when I select all entries in Table B where userId = 1 I’ll also get abdef (and additionally uvwxyz).

Now, the value of abcdef in Table B should replace the value in the selection result of table A. And the uvwxyz-entry should be added to the result.

Finally I’m looking for a query which produces the following table:

id VARCHAR(32) | value VARCHAR(32)
abcdef         | myValue4           -- myValue1 from the select-statement in tableA should be overwritten
mnopqr         | myValue2           -- from table A
uvwxyz         | anotherValue       -- from table B

I hope anyone know how to do this… thanks in advance for any suggestion! By the way… it would be great if there is any chance to realize this using one single (long) select statement.

  • 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-10T22:52:01+00:00Added an answer on June 10, 2026 at 10:52 pm

    Try this:

    SELECT * FROM TableB WHERE userId = 1
    UNION
    SELECT * FROM TableA WHERE groupId = 1 
           and id not in (select id from TableB where userid = 1)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I have just tried to save a simple *.rtf file with some websites and
Basically, what I'm trying to create is a page of div tags, each has
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but

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.