SQL Basics

 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me



Go Back   Tutorialized ForumsDatabasesSQL Basics

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Tutorialized Forums Sponsor:
  #1  
Old March 10th, 2017, 08:10 AM
eka-eka eka-eka is offline
Registered User
Tutorialized Newbie (0 - 499 posts)
 
Join Date: Mar 2017
Posts: 2 eka-eka User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 42 m 31 sec
Reputation Power: 0
SQL exercise

I have users table (Sheet1) with following columns: ID, Name, Surname, ReportingToID. ReportingToID is referring to ID, blank ones are NULLs.

I want a single query that will pull together in one column Surname &', '& Name, second column - Surname (ReportingTo) & ', ' & Name Reporting (To).

I have managed to do it in two queries, but how can I merge them into a single one. See queries below.

Query 1
SELECT [Field5]+', '+[Field4] AS Users, CInt(IIf([Field37]='Null',0,[Field37])) AS exp
FROM Sheet1;

Query 2
SELECT Query1.Users AS [User], [Field5]+', '+[Field4] AS Reports_to
FROM Query1 INNER JOIN Sheet1 ON Query1.exp = Sheet1.Field1
ORDER BY Query1.Users;

Reply With Quote
  #2  
Old March 23rd, 2017, 08:18 AM
eka-eka eka-eka is offline
Registered User
Tutorialized Newbie (0 - 499 posts)
 
Join Date: Mar 2017
Posts: 2 eka-eka User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 42 m 31 sec
Reputation Power: 0
Due to no answers I decided to give practical example. 'OUTPUT; is what I'm trying to achieve from 'Table'.

TABLE
ID |User_name| ReportingTo_ID
1 |Jonh P | NULL
2 |Kate L | 5
3 |David H | 1
4 |Steve W | 5
5 |Jane F | NULL

OUTPUT
User_name| ReportingTo
John P |
Kate L | Jane F
David H | John P
Steve W | Jane F
Jane F |

Last edited by eka-eka : March 23rd, 2017 at 08:22 AM.

Reply With Quote
Reply

Viewing: Tutorialized ForumsDatabasesSQL Basics > SQL exercise


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 

Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.

© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap