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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:02:07+00:00 2026-06-15T22:02:07+00:00

I have two tables Like Below CREATE TABLE projectlist(ProjectId INT NOT NULL PRIMARY KEY,

  • 0

I have two tables Like Below

CREATE TABLE projectlist(ProjectId   INT NOT NULL PRIMARY KEY,
                         ProjectName VARCHAR(50),
                         Location    VARCHAR(50));

CREATE TABLE LocationList(LocaId INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
                          ProjectId INT,
                          Location    VARCHAR(50));

The Values in the table are as Below

INSERT INTO projectlist(ProjectId, ProjectName)
                 VALUES(1, 'Project A'),
                       (2, 'Project B'),
                       (3, 'Project C'),
                       (4, 'Project D'),
                       (5, 'Project E'),
                       (6, 'Project F'),
                       (7, 'Project G'),
                       (8, 'Project H');

INSERT INTO LocationList(ProjectId, Location)
                  VALUES(1, 'Location A'),
                        (1, 'Location C'),
                        (2, 'Location C'),
                        (2, 'Location B'),
                        (2, 'Location A'),
                        (3, 'Location B'),
                        (4, 'Location C'),
                        (5, 'Location D'),
                        (6, 'Location A'),
                        (6, 'Location B'),
                        (7, 'Location B'),
                        (8, 'Location D'),
                        (8, 'Location A');

I want a Insert Query which inserts First LocationList.Location into projectlist.Location for their respective project relating on project id.

So the table projectlist after running query is

   ProjectName                 Location
    Project A                 Location A 
    Project B                 Location C
    Project C                 Location B
    Project D                 Location C
    Project E                 Location D
    Project F                 Location A
    Project G                 Location B
    Project H                 Location D    

I tried a SQL query which bring the First Location from LocationList table as below.

 SELECT DISTINCT MNPCL.Location, MNP.ProjectId
   FROM LocationList MNPCL RIGHT OUTER JOIN
        projectlist MNP ON MNP.ProjectId = MNPCL.ProjectId                            
  GROUP BY MNP.ProjectName

How to write a query which perform insert in the projectlist Location

Thanks For Reply

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

    Here is a SQLFiddle demo

    update projectlist 
    join 
    (
    select LocationList.ProjectID,LocationList.Location 
      from LocationList
    join 
    (select LocationList.ProjectID,min(LocaId) minLocaId 
        from LocationList 
        group by LocationList.ProjectID) l1
            on LocationList.LocaId=l1.minLocaID
     ) l2 on projectList.ProjectID=l2.ProjectID
    SET ProjectList.Location=l2.Location
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have two tables structured like so: CREATE TABLE #nodes(node int NOT NULL);
I have two tables like, CREATE TABLE [dbo].[entry] ( [id] [int] NULL, [service] [int]
I have two database tables with some demo data like shown below Create table
I have a table like below CREATE TABLE `fruits` ( `fruit_id` int(11) default NULL,
I have two table like below CREATE TABLE IF NOT EXISTS `countries` ( `id`
I have two tables which looks something like this Table Queue int ID; string
I have two MySql tables as shown below with the data shown: CREATE TABLE
I have a composite primary key table (Maintenance Items). I would like to create
I'm using SQL Server 2008. Let's say I have two hypothetical tables like below:
I have two tables like the ones below. I need to find what exchangeRate

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.