473,382 Members | 1,348 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Combining 3 Columns into one

f430
43
i need to write a query that combines more than one column together.
one example of what i am trying to do is as follows:

Col 1 Col 2 Col 3
15..... 13..... 10
2..... 9...... 12.5
6..... 5...... 22

Query new colunm
15
2
6
13
9
5
10
12.5
22
However the column fields are text.
Aug 12 '10 #1
10 1490
Stewart Ross
2,545 Expert Mod 2GB
I'm assuming this is not a homework question. If it is our rules do not permit us to answer it.

You need to use a Union query to do what you ask. I can show part of this (thus not giving you the complete answer if it is a homework question) as follows:

Expand|Select|Wrap|Line Numbers
  1. Select [Col 1] from [Your table] UNION
  2. Select [Col 2] from [Your table];
Like any SQL-based query, the values returned form a Set. The ordering of values within a set cannot be guaranteed unless you apply a specific ORDER BY clause in the SQL - but in Union queries you may find that this gives unexpected results.

-Stewart
Aug 12 '10 #2
f430
43
actually what i am trying to do is a bit more complicated, and im not even sure if it is possible.
here is what i am trying to do

Part Number.....Col 1.......Col 2.....Col 3
1........................10..........20........30
2........................11..........__........31
3........................12..........__........__

my question is can i do this:

part number.......New Col
1..................10
2..................11
3..................12
1..................20
1..................30
2..................31

im trying to have a query that replicates the part number if col 2, or col 3 are being used. and then make that a table.
this is not homework, school hasnt even started

Thanks
Aug 12 '10 #3
Stewart Ross
2,545 Expert Mod 2GB
Hi. It helps to know what you want up front, as the solution is not quite the same.

Expand|Select|Wrap|Line Numbers
  1. Select [part number], [col 1] from [Your Table]
  2. UNION
  3. Select [part number], [col 2] from [Your Table] 
  4. WHERE [Col 2] IS NOT NULL 
  5. UNION
  6. Select [part number], [col 3] from [Your Table] 
  7. WHERE [Col 3] IS NOT NULL;
-Stewart
Aug 12 '10 #4
f430
43
where would i enter this in, if i am trying to put it in a query?
Aug 12 '10 #5
NeoPa
32,556 Expert Mod 16PB
You can tag an ORDER BY line to Stewart's SQL if you like :
Expand|Select|Wrap|Line Numbers
  1. ORDER BY [Part Number]
Of course you realise this is on;y necessary because the structure of your table is not normalised (See Normalisation and Table structures).
Aug 12 '10 #6
NeoPa
32,556 Expert Mod 16PB
f430: where would i enter this in, if i am trying to put it in a query?
Open the query (QueryDef) that you want to use it in then select View / SQL View. from there you simply paste it over whatever's there. You won't be able to see it in Design View after that as UNION queries are not supported in that view.
Aug 12 '10 #7
f430
43
Thank you NeoPa, i appreciate your help
Aug 12 '10 #8
NeoPa
32,556 Expert Mod 16PB
No worries. These columns aren't [Defect Code 1] through [Defect Code 3] by any chance are they?
Aug 12 '10 #9
f430
43
they are the defects but im using this modified table for creating diagrams.
i was actually thinking of modifying this a little, if i wanted to do the following

Part Number.....Col 1.......Col 2.....Col 3..Col 4.......Col 5.....Col 6
1........................10..........20........30. ......12..........40........15
2........................11..........21........31. ......12..........__........__
3........................12..........22........__. ......__..........__........__

my question is can i do this:

part number.... Col......Col
1..................10...........20
2..................11...........21
3..................12...........22
1..................30...........12
1..................40...........15
2..................31...........12
Aug 13 '10 #10
NeoPa
32,556 Expert Mod 16PB
f430: my question is can i do this:
No. It's not. That is an entirely new question (You should pay more attention to advice given. Stewart mentioned this earlier). People don't appreciate answering a question correctly only to be told the question has changed. This has happened twice now in this thread already.

If you want to ask a new question then please do so in its own thread.
Aug 13 '10 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: JackT | last post by:
Hi, I have the following SQL SELECT Table1.Col1, Table3.Col1 AS Expr1, COUNT(Table1.Col2) AS Col2_No, COUNT(Table1.Col3) AS Col3_No etc, FROM Table3 INNER JOIN Table2 ON...
8
by: Ilan | last post by:
Hi all I need to add data from two Excel sheets (both on the same workbook) to an existing table in my SQL DB. The problem is that each sheet holds different fields for the same record, though...
5
by: M.Stanley | last post by:
Hi, I'm attempting to create a query that will combine 2 columns of numbers into one. The followng comes from 1 table with 4 fields (A,B,C,D) A B RESULT 700 000 700000 700 001 ...
6
by: Don | last post by:
I'm thinking this is simple and I'm just not understanding how to do it but I have to ask because I'm stumped. I have a query (which is used to create a report) and three of the columns in this...
2
by: ray well | last post by:
i need to display 2 columns of data in a list box. how would i set this up IN CODE. say my table is tblNames, and i have 2 fields, FirstName, LastName, and want the data to show up in 2...
2
by: J055 | last post by:
Hi I need to search a number of DataTables within a DataSet (with some relationships) and then display the filtered results in a GridView. The Columns that need to be displayed come from 2 of...
8
by: Sham | last post by:
I am trying to perform the following query on a table that has been indexed using Full Text Search. The table contains multiple columns than have been indexed. (Below, all xml columns are...
3
by: Ken Fine | last post by:
This is a question that someone familiar with ASP.NET and ADO.NET DataSets and DataTables should be able to answer fairly easily. The basic question is how I can efficiently match data from one...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.