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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T22:46:50+00:00 2026-05-13T22:46:50+00:00

I am trying to select data from two tables and insert it into another

  • 0

I am trying to select data from two tables and insert it into another one. I want to select the data when certain things match in each table. The problem is that one of the comparisons needs to be a like and I am at a loss. The sql statement is below and I believe that it will at least show what I am trying to do.

insert into hr_numbers 
  (`user_id`, `hr_number`) 
  select distinct u.user_id, t.num 
    from temp t, users u 
   where t.name like '%' + u.l_name + '%';

I have tried to use procedures but cannot figure that out or even tell if that would help.

  • 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-13T22:46:50+00:00Added an answer on May 13, 2026 at 10:46 pm

    First, make sure the SELECT is returning what you want before attempting insertion. This:

    SELECT DISTINCT 
           u.user_id, 
           t.num 
      FROM temp t, users u 
     WHERE t.name like '%' + u.l_name + '%'
    

    …is using ANSI-89 JOIN syntax. ANSI-92 join syntax is a better choice:

    SELECT DISTINCT
           u.user_id,
           t.num
      FROM USERS u
      JOIN TEMP t ON t.name LIKE CONCAT('%', u.l_name ,'%')
    

    …but the join criteria looks flawed. It’s going to link rows were the last name appears in the t.name value, leading to the Smith problem: If the last name is “Smith”, all rows will link up – even if the names are John, Jim, etc.

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

Sidebar

Ask A Question

Stats

  • Questions 491k
  • Answers 491k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer SurfaceView enables to work on 2 buffer for drawing, how… May 16, 2026 at 10:04 am
  • Editorial Team
    Editorial Team added an answer CHOICE and ENUMERATED are used for different purposes, as different… May 16, 2026 at 10:04 am
  • Editorial Team
    Editorial Team added an answer I recently released UglifyJS, a JavaScript compressor which is written… May 16, 2026 at 10:04 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

Im using vb.net and I need to fetch data from two different tables and
I have two tables. I am trying to find rows in one table which
I'm trying to write a stored procedure to copy a subset of data from
When I use a rewrite rule that splits an insert into one table into
I'm trying to create a csv export of data from mysql using the following
For example I have the following tables resulting from: CREATE TABLE A (Id int,
I'm using SQL Server 2005. I am migrating data over from a current database
I have two tables as follows PRODUCT table Id | Name | Price And
I am using two different jQuery plugins that I'm trying to combine. First I'm
i'm trying to use mysqli to display data, but it displays nothing. what is

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.