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

The Archive Base Latest Questions

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

I have 2 tables. One is main table and other one is login table.

  • 0

I have 2 tables. One is main table and other one is login table. I may have 10 Records in Main table and 6 Records in login table. Each login id has to be assingned equally to main table. Can any one please give me the best solution to update the login information.

Example

Create table ##t1 
(id int identity,
name varchar(5),
loginid varchar(10)
divno char(3))




create table ##l1
(
id int identity,
name varchar(10),divno char(3))

insert into ##t1 values
('Jin',null,'001')
insert into ##t1 values
('Anu',null,'001')
insert into ##t1 values
('kir',null'002')
insert into ##t1 values
('Asi',null,'003')
insert into ##t1 values
('Nil',null,'002')
insert into ##t1 values
('sup',null,'003')
insert into ##t1 values
('amu',null,'003')
insert into ##t1 values
('mani',null,'003')

insert into ##l1 values
('A','001')
insert into ##l1 values
('B','001')
insert into ##l1 values
('C','002')
insert into ##l1 values
('D','002')
insert into ##l1 values
('E','002')
insert into ##l1 values
('F','003')

Data Example

Main table

id          name  loginid divno
----------- ----- ----------
1           Jin   NULL    001
2           Anu   NULL    001
3           kir   NULL    002
4           Asi   NULL    003
5           Nil   NULL    002
6           sup   NULL    003
7           amu   NULL    003
8           mani  NULL    003

Login Table

id          name    divno
----------- -------------
1           A        001
2           B        001
3           C        002
4           D        002
5           E        002
6           F        003

desired output

enter image description here

How can we do this without looping?

  • 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:04:19+00:00Added an answer on June 10, 2026 at 10:04 pm
     update ##t1 
     set loginid = #l1.name
     from   
          ##t1
               inner join 
          (select *, (ROW_NUMBER() Over (order by id) -1)% (select COUNT(*) from ##l1)+1 as rn from ##t1) v
               on ##t1.id = v.id
               inner join 
          ##l1 
               on v.rn = ##l1.id
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have four different tables, one main SPECIAL table containing only id's that reference
I have two tables : one table it matchs and the other is teams.
I have a model which has one main table with 22 fields and 5
I have 2 tableViews, the first one is the Main table and the second
I have two tables one with ID and NAME table 1 ID | NAME
I have two tables one called fs_note the other called dumy_fs_note I created after
I have two tables connected with one to many relationship. Parent Table is a
I have ten master tables and one Transaction table. In my transaction table (it
I have two tables on mysql: users, and management. The users table has a
I have two tables that are related to each other in a 1-1 relationship

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.