473,856 Members | 1,762 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Same Column, Same Table - Query

9 New Member
good day.

sample database:


col1 col2 col3
A item1 100
A item2 200
A item3 300
B item1 400
B item2 500
B item3 600

############### ############### ###

query result:

col1 col2 col3 col4 col5
item1 A 100 B 400
item2 A 200 B 500
item3 A 300 B 600

is this possible to do a query with this result.

thank you.
Oct 7 '14 #1
15 1939
9,735 Recognized Expert Moderator Expert

Is this a SQL Server question or an HTML question?
What technology are you using to implement your solution?

What are you trying to do?
Oct 7 '14 #2
Bala Kumaran
30 New Member
Yes It is possible getting from Sql. But, you need have use one of the script below to get result from sql.

Oct 7 '14 #3
9 New Member

thank you for the reply.

- This is for MS SQL Server.
- Im using SQL Server Management Studio Express to test the sql query, then i will use it in MS Excel to export data from sql server to MS Excel.
Oct 8 '14 #4
2,878 Recognized Expert Specialist
Yes it's possible. Just JOIN the two tables by COL2

Happy Coding!!!

~~ CK
Oct 8 '14 #5
9 New Member

thanks for the reply.

its only 1 table.
Oct 8 '14 #6
12,516 Recognized Expert Moderator MVP
You can join a table to itself
Oct 8 '14 #7
9 New Member
here is my query code
Expand|Select|Wrap|Line Numbers
  1. USE [SSI-HQ]
  4.     [SSI$Sales Price].[Sales Code]
  5.     ,[SSI$Sales Price].[Item No_] AS [Item No]
  6.     ,[SSI$Sales Price].[Variant Code]
  7.     ,[SSI$Sales Price].[Unit of Measure Code] AS [Unit of Measure]
  8.     ,[SSI$Sales Price].[Unit Price] AS SALES1
  9.     ,[SSI$Sales Price].[Unit Price] AS SALES2
  10.     ,SSI$Item.[Unit Cost]
  11.     ,[SSI$Sales Price].[Starting Date]
  12.     ,[SSI$Sales Price].[Ending Date]
  15. FROM [SSI$Sales Price]
  17. LEFT JOIN SSI$Item
  18.     ON [SSI$Sales Price].[Item No_] = SSI$Item.No_
  20. JOIN [SSI$Sales Price]
  21.     ON [SSI$Sales Price].[Item No_] = [SSI$Sales Price].[Item No_] AND [SSI$Sales Price].[Variant Code] = [SSI$Sales Price].[Variant Code] 
  23. WHERE
  24.     [SSI$Sales Price].[Sales Code] = 'C00020' AND
  25.     [SSI$Sales Price].[Sales Code] = 'SRP' AND
  26.     [SSI$Sales Price].[Sales Type] = '0' 
Oct 8 '14 #8
9 New Member
error message

Msg 1013, Level 16, State 1, Line 3
The objects "SSI$Sales Price" and "SSI$Sales Price" in the FROM clause have the same exposed names. Use correlation names to distinguish them.
Oct 8 '14 #9
9 New Member
here is revised query:

Expand|Select|Wrap|Line Numbers
  2.     [SSI$Sales Price].[Sales Code] AS CUSTOMER
  3.     ,[SSI$Sales Price].[Sales Code] AS SRP
  4.     ,[SSI$Sales Price].[Item No_] AS [Item No]
  5.     ,[SSI$Sales Price].[Variant Code]
  6.     ,[SSI$Sales Price].[Unit of Measure Code] AS [Unit of Measure]
  7.     ,[SSI$Sales Price].[Unit Price] AS SALES1
  8.     ,[SSI$Sales Price].[Unit Price] AS SALES2
  9.     ,SSI$Item.[Unit Cost]
  10.     ,[SSI$Sales Price].[Starting Date]
  11.     ,[SSI$Sales Price].[Ending Date]
  14. FROM [SSI$Sales Price]
  16. LEFT JOIN SSI$Item
  17.     ON [SSI$Sales Price].[Item No_] = SSI$Item.No_
  19. JOIN [SSI$Sales Price] AS CUSTOMER
  20.     ON [SSI$Sales Price].[Item No_] = [SSI$Sales Price].[Item No_] AND [SSI$Sales Price].[Variant Code] = [SSI$Sales Price].[Variant Code] 
  22. JOIN [SSI$Sales Price] AS SRP
  23.     ON [SSI$Sales Price].[Item No_] = [SSI$Sales Price].[Item No_] AND [SSI$Sales Price].[Variant Code] = [SSI$Sales Price].[Variant Code] 
  25. WHERE
  26.     [SSI$Sales Price].[Sales Code] = 'C00020' AND
  27.     [SSI$Sales Price].[Sales Code] = 'SRP' AND
  28.     [SSI$Sales Price].[Sales Type] = '0'
after i run the query nothing happen, no error message
Oct 8 '14 #10

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

Similar topics

by: Heist | last post by:
Hi, I just want to know to turn this: CREATE TABLE . ( NOT NULL , (50) COLLATE French_CI_AS NULL , NOT NULL , (50) COLLATE French_CI_AS NOT NULL , NULL , NULL ) ON into this:
by: pb648174 | last post by:
I have a single update statement that updates the same column multiple times in the same update statement. Basically i have a column that looks like . which are id references that need to be updated when a group of items is copied. I can successfully do this with cursors, but am experimenting with a way to do it with a single update statement. I have verified that each row being returned to the Update statement (in an...
by: PMB | last post by:
Thank you in advance for any and all assistance. I'm trying to use a make table query to pull the last transactionID, so I can use an append query to reset the transactionID to the next sequential number. My problem is, the make table query is taking all the TransactionID's and putting them in the new table. Is there a way to take the last transactionID only and put it in the new table? So this way, when I clear the old Transactions,...
by: Alan Lane | last post by:
Hello world: I'm including both code and examples of query output. I appologize if that makes this message longer than it should be. Anyway, I need to change the query below into a pivot table query. I'm having trouble doing it. Help! Here is my code so far: Sub OldRegionQuery()
by: ste | last post by:
Hi there, I'm trying to query a MySQL database (containing image data) and to output the results in a HTML table of 3 columns wide (and however many rows it takes) in order to create a basic thumbnail gallery. I can query and output the data as a single column table, but I'm having problems filling up a 3 column table (with different images, looping continuously until the end).
by: Volition | last post by:
I have looked around and can't find any help for my SQL problem. I have a Table which lists people peopledb. _____________ id | Name 1 | Fred 2 | Bill 3 | Bob
by: Robertf987 | last post by:
Hi, I'm a bit stuck with an access database. I'm using access 2000 if that's any help. Right, it's 3:40am right now and I'm rather tired, but I *hope* this makes sense. I have a table which contains the main data of the database, records of information of grants. For each financial year, the old data needs taking out of the table. Basically I have two options: delete the old data from the year before, or back it up in a new table. I'd rather...
by: pl1 | last post by:
Hi everyone, I'm using MS-Access 2003, OS: Window XP Professional sp3. In Northwind database (sample Database),the Suppliers table have column "SupplierID" which is also present in Products table, my question is how can I use same column in 2 tables without entering data in them manually Also the relationship between 'Suppliers' table and 'Products' table is one-to-many. The column type in Products table for column "SuppliersID" is...
by: Captain Jack Sparrow | last post by:
I have a column in a table named "Hospice". I have a make table query that pulls in this column but renames the column in the result to "Hospice (Yes/No)". The column name in the resulting table is "Hospice(Yes/No)", and the query design (after being saved) also shows "Hospice(Yes/No)" as the alias for the new column. Both the query and the resulting table remove the <spacebetween the "e" in Hospice and the open "(". Any ideas? TIA.
by: Mihail | last post by:
Hi all ! What I have: In a BE database I use a temporary table to store some data. Of course, for different filters that data will be different. Keep in mind, please, that the table structure is not changed. Only data. In a FE database I have - A make table query based to the temporary table from BE. This is a simple query which simple transfer the temporary table from the BE to FE - 2 command buttons: cmdStore_1 and cmdStore_2
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.