From a high level, you'd simply do this:
SELECT *
FROM dbo.member m
INNER JOIN dbo.tasklist_data tld ON m.UID = tld.TaskID;
The INNER JOIN
will take rows from dbo.member
where the UID
column values match values contained in the TaskID
column from the tasklist_data
table. If you wanted ALL the rows from dbo.member
, and only matching rows from dbo.tasklist_data
, you'd rewrite that as:
SELECT *
FROM dbo.member m
LEFT JOIN dbo.tasklist_data tld ON m.UID = tld.TaskID;
Steve Stedman has an excellent resource for understanding how the different types of JOIN
statements work.
If you need to do this on more than two tables, you simply add JOIN
clauses as necessary:
SELECT *
FROM dbo.member m
INNER JOIN dbo.tasklist_data tld ON m.UID = tld.TaskID
INNER JOIN dbo.some_other_table sot ON m.UID = sot.some_column_name;
I have broken a (arguably) cardinal sin above by using SELECT *
to return all columns from all of the tables mentioned in the FROM
clause of the query. It is generally considered good practice to explicitly specify the columns required, for instance:
SELECT m.UID
, m.SomeColumn1
, m.SomeColumn2
, tld.TaskID
, tld.SomeColumn3
FROM dbo.member m
INNER JOIN dbo.tasklist_data tld ON m.UID = tld.TaskID;
SELECT name, MIN(type) AS type
FROM table_name
GROUP BY name
HAVING COUNT(DISTINCT type) = 1 ;
or the same with:
HAVING MIN(type) = MAX(type)
I assume that type
is not nullable.
If you want only those that have type = 'a'
, use:
HAVING MIN(type) = 'a'
AND MAX(type) = 'a' ;
Best Answer
You can just add the new column to the table as nullable, either with SQL Server Management Studio by right clicking on the Table and clicking "Design" or by using an
ALTER TABLE
statement like thisALTER TABLE TableName ADD NewColumnName DataType NULL
.Then you can
UPDATE
that new column from the old column like so: