SQL
SQL
1. A general rule of thumb is that OUTER JOINs cause the number of rows in a result set to
increase, while INNER JOINs cause the number of rows in a result set to decrease. Of course,
there are plenty of scenarios where the opposite is true as well, but it's more likely to work this
way than not. What you want to do is keep the size of the result set as small as possible for as
long as possible.
Since both joins match on the first table, changing up the order won't effect the accuracy
of the results. Therefore, you probably want to do the INNER JOIN before the LEFT
JOIN:
I have two tables: table1, table2. Table1 has 10 columns, table2 has 2 columns.
3
SELECT * FROM table1 AS T1 INNER JOIN table2 AS T2 ON T1.ID = T2.ID
I want to select all columns from table1 and only 1 column from table2. Is it possible to do that
without enumerating all columns from table1 ?
SELECT t1.*, t2.my_col FROM table1 AS T1 INNER JOIN table2 AS T2 ON T1.ID = T2.ID
One of the best ways to increase query performance is to use indexes. You'll see a marked increase in
performance, especially in situations where you're dealing with hundreds of thousands of records in
the table you're querying. For instance, I had written code to join two tables in Paradox. One table had
1.5 million records in it and the other had maybe a few hundred. When run without indexes on either
table.
You can use Index Tuning Wizard to improve the performence in SQL Server.
If you perform regular joins between two or more tables in your queries, performance
will be optimized if each of the joined columns have their own indexes. This includes adding
indexes to the columns in each table used to join the tables. Generally speaking, a clustered
key is better than a non-clustered key for optimum JOIN performance. [6.5, 7.0,