SQL Tips – Inner Join Select

SELECT tabela1.*, tabela2.Shares, tabela3.domainID
FROM
(SELECT ID, col2, col3, col4
FROM tabela1) tabela1
INNER JOIN
(SELECT col1,COUNT(col1) AS Shares FROM tabela2
GROUP BY col1) tabela2
ON tabela1.ID = tabela2.col1 INNER JOIN
(SELECT col1, col2 FROM tabela2) AS tabela3
ON tabela3.col1= tabela2.col1

TRUNCATE TABLE WITH FOREIGN KEY
dbcc checkident (numeTabela,reseed,1)

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s