user676421
user676421

Reputation: 11

query in sql server 2005

there are two tables ...know i need

1st condition: all the records in table

2 nd condition:

In table2 i need only records which have data

...i want one query for the aove two conditions...

Upvotes: 0

Views: 45

Answers (1)

John Hartsock
John Hartsock

Reputation: 86882

SELECT
  *
FROM Table1 t1
INNER JOIN Table2 t2 on t1.PK = t2.FK

This will return all rows in table1 that have at least one corresponding row in table2

But if you want all rows from t1 no matter what then this may be what you want

SELECT
  *
FROM Table1 t1
LEFT JOIN Table2 t2 on t1.PK = t2.FK

Finally, As I dont know the structure in place perhaps table1 and table2 have similar structures. If this is true perhaps you may want a union of the two

SELECT
  *
FROM Table1 t1
UNION ALL
SELECT
  *
FROM Table2 t2

Upvotes: 1

Related Questions