-4

In sql I have one blank table and second one with values

In me second one I have column with values like

poland-data
russia-data
usa-data
england-data
poland-data-hr
england-data-hr
england-hr
poland-hr 

I want to copy to the blank table column with values without 'hr' from table nr.2 for example i only want to see in that table

poland-data
russia-data
usa-data
england-data
RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
Hw3zs
  • 7
  • 6

2 Answers2

0

You can try following approach:

SELECT distinct REPLACE(col1 ,'-hr', '') as col1
INTO TableTwo 
FROM TableOne 
Aura
  • 1,283
  • 2
  • 16
  • 30
0

It's not entirely clear what you are asking. Is this a specific case of something that will have to be done many times with variable columns? If not, you should be able to just to

CREATE TABLE TABLE_2 AS 
    SELECT poland_data,
           russia_data,
           usa_data,
           england_data
      FROM TABLE_1;

Or

INSERT INTO TABLE_2
    SELECT poland_data,
           russia_data,
           usa_data,
           england_data
      FROM TABLE_1;

If you already have the table created.

Error_2646
  • 2,555
  • 1
  • 10
  • 22
  • I dont think this is a Create table requirement if you look carefully at the question – RiggsFolly Oct 11 '21 at 16:05
  • @RiggsFolly Yes, I added the insert in case the table was already created – Error_2646 Oct 11 '21 at 16:06
  • poland-data russia-data usa-data england-data poland-data-hr england-data-hr england-hr poland-hr this is everything in one column, and i want to copy and put that column in second table without 'hr' rows in names – Hw3zs Oct 11 '21 at 16:07
  • @Hw3zs Please provide sample data and your expected result. "poland-data russia-data usa-data england-data poland-data-hr england-data-hr england-hr poland-hr is everything in one column" doesn't make sense to me. – Error_2646 Oct 11 '21 at 16:08
  • insert into table 2 select column_countries where column_countries not like '%hr' will be fine ? – Hw3zs Oct 11 '21 at 16:08
  • @Hw3zs Okay, I think I see. These are values in a country column. Alright. In that case yeah, just insert with that like condition. – Error_2646 Oct 11 '21 at 16:10