268 Part I EXAM PREPARATION SELECT statement in
268 Part I EXAM PREPARATION SELECT statement in the list must return the same number of columns, and the columns must be of compatible types. So, if the first SELECT statement returns an int, a float, a varchar(15), and a char(6), the second has to contain two pieces of data that can be converted to numbers followed by two pieces of data that can be converted to characters. So, what happens if the columns are different types? Well, if they are compatible, meaning that the types and data can be implicitly converted, then the output set will contain as close to the types of the first SELECT as possible, with the following rules for a given column: If any of the SELECT statements return a mix of variable-length and fixed-length fields, the output is variable length. If the SELECT statements contain columns of different lengths, the longest length is used for the output. If the two values are numerics, the value with the most precision is used. So, if you have an integer and a float, the output is a float, because a float has the most precision. If you have an integer and a string that is a number (such as 42), then you will have an integer; but, if the string was 42.00, you d have a numeric type that could contain two decimal places and a full integer. These are the rules of thumb that ll get you through most situations. If you want to see the entire set of data type precedence rules, it is available in blogs Online. Search the index for Precedence, and choose the article on Data Type Precedence. Here s an example of a UNION. This example uses a different set of sample data than the rest of the chapter, because of the type conversion topics: CREATE TABLE Table1 ( A int, B float, C varchar(15), D char(10) ) CREATE TABLE Table2 ( First numeric(5,2), Second int, Third int )
If you looking for unlimited one inclusive web hosting plan please check cheap web hosting website.