LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 07-04-2012, 04:38 AM   #1
fhleung
Member
 
Registered: Aug 2004
Distribution: Fedora, Debian
Posts: 327

Rep: Reputation: 30
SQL statements howto -- 3 columns input but 2 columns output


Hi folks, this is my first time to post in this programming sub forum.

I got questions on SQL statement, please visit:
http://protrek.com.hk/test/q.html

Last edited by fhleung; 07-04-2012 at 04:54 AM.
 
Old 07-04-2012, 05:31 AM   #2
Snark1994
Senior Member
 
Registered: Sep 2010
Location: Wales, UK
Distribution: Arch
Posts: 1,630
Blog Entries: 3

Rep: Reputation: 345Reputation: 345Reputation: 345Reputation: 345
It is far more normal to post your problem in your own post - for example, if that site goes offline, there's no record of your question.

Quote:
I got 3 columns, name, col1, col2, I want to output 2 columns only
col1== col2 OR col1!=col2 in each row
but my final output only 2 column
INPUT:
Code:
	name 	col1 	col2
row1 	A 	1 	1
row2 	B 	2 	22
row3 	C 	3 	333
row4 	D 	4 	4
OUTPUT:
Code:
	name 	column 	
row1 	A 	1 	
row2 	B 	2 	
row3 	B 	22 	
row4 	C 	3 	
row5 	C 	333 	
row6 	D 	4
is what you have on the link,

and the answer is:

Code:
(SELECT name, col1 FROM `test`) UNION (SELECT name, col2 FROM `test`)
 
Old 11-28-2012, 10:36 PM   #3
fhleung
Member
 
Registered: Aug 2004
Distribution: Fedora, Debian
Posts: 327

Original Poster
Rep: Reputation: 30
Dear Snark1994,

Thank you for the repsond. Thank you for the keyword UNION

It is work and HELPFUL! Thank you once again!
 
Old 11-29-2012, 10:45 AM   #4
Snark1994
Senior Member
 
Registered: Sep 2010
Location: Wales, UK
Distribution: Arch
Posts: 1,630
Blog Entries: 3

Rep: Reputation: 345Reputation: 345Reputation: 345Reputation: 345
No problem, glad it helped. Please mark the thread as "SOLVED" so others know it contains a solution.

Thanks,
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] AWK: add columns while keep format for other columns cristalp Programming 3 10-13-2011 06:14 AM
trying to add df output columns help alienmindvision Programming 5 06-06-2009 12:34 PM
sed script to read only columns 4 to 6 in output database cranium2004 Programming 10 02-28-2006 07:20 AM
printf: postion cursor to output columns schneidz Programming 5 09-20-2005 08:59 AM
Removing Columns From Output darthtux Programming 4 08-01-2004 09:21 PM


All times are GMT -5. The time now is 12:00 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration