Yeah, thats correct. The next step will be to get the values like this:
x;x;x;x; in one field.
I also can do this at client side, but want to give it a try.
> Arjen wrote:
>> Hi,
>>
>> I have a select statement that selects data out of three tables, like
>> this.
>> SELECT DISTINCT * FROM table1, table2, table3 WHERE table1.name = 'x'
>> OR table2.name = 'x' OR table3.name = 'x'
>>
>> Well, this is just an example. The real statement is bigger.
>> When I run this query with two tables then there is no problem, but
>> when I run the statement with three tables then I get a huge
>> performance drawback. I have changed table1 with table3, but still see
>> problems... so, three tables is to much.
>>
>> Now I need to select out of these three tables, with the distinct
>> function.
>>
>> Is there an other way? I.e. first select each table, then combine and
>> select distinct.
>>
>> Thanks!
>> Arjen
>
> Avoid using SELECT * in your production code. I expect you can use UNION
> to get the answer you want:
>
> SELECT col1, col2, col3, ...
> FROM table1
> WHERE name = 'x'
> UNION
> SELECT col1, col2, col3, ...
> FROM table2
> WHERE name = 'x'
> UNION
> SELECT col1, col2, col3, ...
> FROM table3
> WHERE name = 'x' ;
>
> With good design this shouldn't usually be necessary because it's a
> mistake to repeat the same columns in different tables where the values
> potentially have a common key.
>
> --
> David Portas, SQL Server MVP
>
> Whenever possible please post enough code to reproduce your problem.
> Including CREATE TABLE and INSERT statements usually helps.
> State what version of SQL Server you are using and specify the content
> of any error messages.
>
> SQL Server Books Online:
>
http://msdn2.microsoft.com/library/ms130214(en-US,SQL.90).aspx
> --
>
>