473,396 Members | 2,017 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,396 software developers and data experts.

How to merge rows from a Virtual Table, based on a foreign key

The following is the sample result of a large SQL SELECT Statement, from a single table. I have used --- to show the X values under each column

CODE------XX-------------YY-----------------ZZ
AD------------X-----------------------------------
AD-----------------------------------------------X
AD---------------------------X--------------------
CD------------X-----------------------------------
CD-----------------------------------------------X
CD---------------------------X--------------------

I would like to further refine the above results by merging onto a single row for each CODE. Example below.

Please note that each row for each code, will have only one value. So, using a CONCAT feature would be fine for me. I am at a loss to identify the parent SQL Statement to merge the data as below

CODE--XX--YY--ZZ
AD-------X---X---X
CD-------X---X---X

Request help from folks on this forum
Oct 19 '10 #1
1 2283
amitpatel66
2,367 Expert 2GB
Try this:

Expand|Select|Wrap|Line Numbers
  1. SQL> with t as (select 'AD' col1,'X' xx,NULL yy,NULL zz from dual
  2.   2  union select 'AD',NULL,NULL,'X' from dual
  3.   3  union select 'AD',NULL,'X',NULL from dual
  4.   4  union select 'CD','X',NULL,NULL from dual
  5.   5  union select 'CD',NULL,'X',NULL from dual)
  6.   6  SELECT col1,MAX(xx),MAX(yy),MAX(zz) FROM t
  7.   7  GROUP BY col1;
  8.  
  9. CO M M M
  10. -- - - -
  11. AD X X X
  12. CD X X
  13.  
  14. SQL> 
  15.  
Oct 19 '10 #2

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

Similar topics

0
by: Enrico Del Grosso | last post by:
Hello everyone, i'm new here and i need a little help from some DataTable experts. I'm using a System.DataTable to fill a Datagrid in a window application, and I need that some rows and columns of...
0
by: Ron VanDerMaarel | last post by:
Hi all, When trying to delete a record from a table, I receive the message " ERROR 1217: Cannot delete or update a parent row: a foreign key constraint fails". I know there is a foreign key,...
3
by: Raghuram Banda | last post by:
Hi, I was strucked in a problem, basically I'm working on Sortable Table and the table is created using HTML Tags and one of the fields in the table contain Date in unix format (something like...
0
by: tnks | last post by:
Hello i need to save a virtual table (dataset table) into a SQL table somo one know how to do it ?? (this is part of my code) Dim sqladapt As SqlDataAdapter Dim dsOC As New DataSet Dim...
1
by: sbcaco | last post by:
hello, I'm using sql server 2000. I have a table that contains unique prodnames ("Table A" -100 rows). I want one record with all of the fields from a table ("Table B" - 5128 rows) for each of...
4
by: djpaul | last post by:
Hello, I have a database (mysql) with a lot of music in it. Now i have wrote a page where users can request a song and it plays it automatically. But, i don't want to have that somebody is...
28
by: CatrionnaRain | last post by:
Hi All - I'm using 2002 and consider myself an intermediate Access user but newbie programmer :) I've been tasked with the db project from hell and have been combing through posts for the last...
1
by: djl531 | last post by:
SQL 2005 database. What I have is a database with user info in it. It is a list of names, dob, drivers license numbers, etc. I have an update that i need to merge into it. So I have an identical...
8
by: Fluffygoldfish | last post by:
Hi I am trying to tidy up an access database that has traditionally just been used as a spreadsheet. I have split up the information into different tables and need some help transferring...
5
by: truptivk | last post by:
Hello all, I have a question and I'd be glad if any of you could help me :) I have written code to add rows dynamically to an existing table. When the user first comes to the page, there are 2...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.