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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T20:52:28+00:00 2026-06-05T20:52:28+00:00

Hello to whomever wishes to bite his teeth on this, I came across multiple

  • 0

Hello to whomever wishes to bite his teeth on this,

I came across multiple examples of how to use the result set of subquery select into another table.
What I have however is:

SELECT `klanten_zakelijk`.`bedrijfs_id`, `klanten`.`klant_id` 
    FROM `klanten`,`klanten_zakelijk`
    WHERE `klanten`.`emailadres` = '$email' 
    AND `klanten_zakelijk`.`bedrijfs_kvk`='$kvknr'

As you can see I take the results from two different tables and need to port them to another table.

I wish to insert those values into the table klant_bedrijf_machtiging.

INSERT INTO `klant_bedrijf_machtiging` (`klant_id`, `bedrijfs_id`, `machtiging`) VALUES ('8501', '1', '3');

The column machtiging is is standard 3 with an insert but I need to be able to change that as well to 1 if the company already exists, but I will intercept that at another part of my code.

All the examples I saw were just the results from one table being imported into anther table.
Does that same logic apply when you take results from two tables? If so, what would be the wisest and most efficient way to implement this?

So to make the question short:
How do I get bedrijfs_id and klant_id into the corresponding columns into klant_bedrijf_machtiging whilst still myself being able to manipulate the last column machtiging in just 1 query.

  • 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-05T20:52:30+00:00Added an answer on June 5, 2026 at 8:52 pm

    Good news! MySQL has an easy way to do this: MySQL Insert Into w/ Select

    So in your case it would be:

    INSERT INTO klant_bedrijf_machtiging (`klant_id`, `bedrijfs_id`, `machtiging`)
    SELECT `klanten`.`klant_id`, `klanten_zakelijk`.`bedrijfs_id`, 3
        FROM `klanten`,`klanten_zakelijk`
        WHERE `klanten`.`emailadres` = '$email' 
        AND `klanten_zakelijk`.`bedrijfs_kvk`='$kvknr'
    

    As for changing the item to 1 if it already exists, I am not sure how you would do that in one query without making a huge mess of it.

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

Sidebar

Related Questions

Hello I have like this 2 tables class User public int UserId{get;set;} { ....
hello i hace problem this code : ListenerCrud.php <?php namespace mio\mioBundle; use Doctrine\ORM\Event\PreUpdateEventArgs; use
Hello Guys I am trying to figure out why i am gettings this error
Hello I have this problem with PyQt4-dev-tools that include: * a user interface compiler
Hello and thank you in advance. I know this is total noob question, and
Hello i have this code var queue = new BlockingCollection<int>(); queue.Add(0); var producers =
Hello fellow developers... just to make sure, I want to ask this question: How
Hello I'm a newcomerin JavaScript language. I started to see some examples of JavaScript
. Hello, In Interface builder it really easy to set the order of items,
Hello i'm having some trouble in displaying multiple pushpins on maps. So far i've

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.