Column wise listing

am_sarath

Registered User.
Local time
Today, 22:48
Joined
Sep 19, 2001
Messages
29
Hello

I am trying to display records in my list box from 3 tables using the following query.

SELECT [Field1],[Field2] FROM Table1 UNION SELECT[Field1],NULL FROM Table2; UNION SELECT [Field1],NULL from Table3;

I am able to list all the records in the list box from my tables.
but, i want it to be listed in column wise.

Like it should look in the following fashion in my list box.

FIELD1 FIELD2 FIELD1 FIELD1
(Table1) (Table1) (Table2) (Table3)

How can it be done.any suggestions would be appreciated.
 
SELECT [Field1] AS [NewFieldName1], [Field2] AS [NewFieldName2], NULL AS [NewFieldName3], NULL AS [NewFieldName4] from Table1

UNION SELECT NULL AS [NewFieldName1], NULL AS [NewFieldName2], [Field1] AS [NewFieldName3], NULL AS [NewFieldName4] from Table2

UNION SELECT NULL AS [NewFieldName1], NULL AS [NewFieldName2], NULL AS [NewFieldName3], [Field1] AS [NewFieldName4] from Table3
 
You didn't carry your example far enough for me to determine what you are actualy trying to do. Are the three tables related by some common field? If they are you need to do a join rather than a union.

To show the columns horizontally, you will need to make a form or report with the columns property set to what ever will fit comfortably on the form/page. The columns can be filled either across or down depending on the settings. However, the way your query is now, you will see the null fields from the second two tables interspersed with the filled columns. To eliminate this problem you will need to change your query to do 4 unions rather than the current three. Break the first select into two so that each one only selects one column. Then the second two queries only need to select a single column and they don't need the "dummy" fields.
 

Users who are viewing this thread

Back
Top Bottom