Gowtama Krishna Gowtama Krishna - 6 months ago 39
SQL Question

while creating a table select one column from another table sql

Is there a way to select only one column from other table in a single SQL statement without using Alter again after creating a table with new columns

like below but its just for understanding

create table compliance_rules_filter_groups
( group_id int,
group_name varchar(50),
rule_id int (select rule_id from compliance_rules),
m_group_filter_logical_condition varchar(10)


You are creating table column rule_id as int not, inserting data in this statement. You can use rule_id from compliance_rules table while you are going to insert data to compliance_rules_filter_groups table.

While inserting you may do as following or INNER JOIN could be used depends on your table structure. But after all main thing is, you can't insert data with CREATE statement.

INSERT INTO compliance_rules_filter_groups(group_id, group_name, rule_id, m_group_filter_logical_condition)
SELECT 1, '', (select rule_id from compliance_rules), ''