+ 1
Hi guys, Anyone knows how can I add a column after join table or execute in first table in SQL?
I distinct a column after execute, Idk how can I add it in initial table.
4 Antworten
+ 3
I have re-read your question over and over and still don't understand what is your point exactly.
The statement in your recent post didn't include a JOIN. And I still have no idea how your tables are connected one another.
I will assume you want to select some fields from several joined tables, and insert the selected records into a new table.
Let's say your employees data are scattered over 3 tables like:
e_data
e_id int primary
fullname varchar(50)
age tinyint
e_contact
e_id int *
address varchar(50)
phone varchar(50)
e_divisions
e_id int *
divname varchar(20)
(*) reference to e_data.e_id
if you want to mix the scattered data into table "emps" you go like:
INSERT INTO emps (e_id,fullname,age,address,phone,divname)
SELECT d.e_id,fullname,age,c.address,c.phone,v.divname FROM e_data d INNER JOIN e_contact c ON c.e_id=d.e_id INNER JOIN e_divisions v ON v.e_id=d.e_id;
P.S. Currently not on a computer, so I haven't verify the statement, but I think that's about it.
Hth,
+ 5
Hi @Reza,
Would you mind to post a part of the sql script you are working on? I'm not sure I understand your point and your target, a little more detail wouldn't hurt if you don't mind.
Do you:
1. want to add a new column to a table, or some tables that you want to join?
2. want to select fields from joined tables and have one extra column in the query result?
3. want to select fields from joined tables and store them into a new table?
+ 1
Thank you so much for your help. 💐💐💐
0
Hi @ipang,
Thank you for your attention,
For example after I joined 2 tables, I would add the result's column to table 1.
Another thing with this script:
Select columnname, count(*) as 'new' from table1
group by columnname;
In this instance I'd join or add the results from new column to table1 if it's possible.