473,413 Members | 1,733 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,413 software developers and data experts.

SELECT DISTINCT from two tables

Hi

I have two table which are related:

table1 holds personellinformation
table2 holds nodeInformation

The nodes in table2 can have a nodeOwner which will then get a recordID from
table1. A person can own multiple nodes.

Now I want to display all nodeowners, but not the duplicates (if they own
multiple nodes).

What would be the SQL syntax for that, using ASP with VB?

I've tried using DISTINCT, but I do also need the NodeID which is always
unique so I still get all duplicates.
Hope you can help!
Jul 19 '05 #1
4 6143
> I've tried using DISTINCT, but I do also need the NodeID which is always
unique so I still get all duplicates.


If you need the nodeID, how could you not get duplicates for a person owning
multiple node?
How could the select statement now which nodeID you want to select?

Bingo
Jul 19 '05 #2
> Now I want to display all nodeowners, but not the duplicates (if they own
multiple nodes).

I've tried using DISTINCT, but I do also need the NodeID which is always
unique so I still get all duplicates.


Your requirements conflict with each other. Please give us meaningful
requirements (e.g. actual table structure - including keys and datatypes,
sample data, and desired results).

http://www.aspfaq.com/5006
Jul 19 '05 #3
Marco Alting wrote:
Hi

I have two table which are related:

table1 holds personellinformation
table2 holds nodeInformation

The nodes in table2 can have a nodeOwner which will then get a
recordID from table1. A person can own multiple nodes.

Now I want to display all nodeowners, but not the duplicates (if they
own multiple nodes).

What would be the SQL syntax for that, using ASP with VB?

I've tried using DISTINCT, but I do also need the NodeID which is
always unique so I still get all duplicates.
Hope you can help!


It sounds as if you need to group by node id instead of using distinct, but
I can't be sure without seeing sample data and desired results.

Bob Barrows
Jul 19 '05 #4
"Marco Alting" <ma***@alting-multimedia.nl> wrote in message
news:y8**********************@amsnews02.chello.com ...
.. . .
Now I want to display all nodeowners, but not the duplicates (if
they own multiple nodes).
You SQL for this one should look something like this :

Select Distinct NodeOwner
From table1 t1
, table2 t2
where t1.[ownerID?] = t2.nodeOwner

That will get you all the people that own Nodes, regardless of
how many.
I've tried using DISTINCT, but I do also need the NodeID which
is always unique so I still get all duplicates.


Now you have a problem. If you want Owner /and/ Node, you're
going to get duplication; there's no way around that. If you wanted,
say, a Grouped List of Owners and their Nodes, you'd need
something like this

Select Distinct NodeOwner
, NodeID
From table1 t1
, table2 t2
where t1.[ownerID?] = t2.nodeOwner
Order By t1.[ownerID?]
, t2.nodeID

Then

rsData.Open( [SQL], oDBConnection )

Do While Not rsData.EOF

sCurrentOwner = rsData( "[ownerID?]" ).Value

' [Start] Display Owner

Do While Not rsData.EOF
' Bit of a kludge since VBScript doesn't short-circuit If's
If sCurrentOwner <> rsData( "[ownerID?]" ).Value Then
Exit Do
End If

' Display Node

rsData.MoveNext
Loop

' [End] Display Owner (if, say, you're using HTML tables)

Loop

HTH,
Phill W.
Jul 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: BobG | last post by:
-- The issue This following query works fine on Toad and PowerBuilder yet when it is run on SQLPlus I get: "ORA-03113: end-of-file on communication channel" When I remove the distinct from the...
14
by: Craig Hoskin | last post by:
Hi everyone Have a problem I would areally appreciate help with. I have 3 tables in a standard format for a Bookshop, eg Products Categories Categories_Products the latter allowing me to...
5
by: Reestit Mutton | last post by:
Hi, I'm currently learning the ropes with CSS, PHP, MYSQL, Javascript etc... by redesigning my website as a database driven site. Okay, so I'm skilled at perl, data manipulation and data...
1
by: anmar | last post by:
I'm trying to figure out how to select all the records in one table which have multiple specified records in a second table. Here's a simplified version of my problem. I have two tables,...
2
by: mfyahya | last post by:
I have two tables, both containing an 'authors' column. Is there a way to get a unique list of authors from the two tables? I tried SELECT DISTINCT `authors` from `table1`, `table2`; but I got an...
2
by: Michael Howes | last post by:
I have a single DataTable in a DataSet. It has 4 columns and i'd like to get a handful of counts of unique items in 3 of the 4 columns. Can a DataTables Select or Compute methods to COUNT DISTINCT?...
4
by: Ed L. | last post by:
I think I'm seeing table-level lock contention in the following function when I have many different concurrent callers, each with mutually distinct values for $1. Is there a way to reimplement...
1
by: zafm86 | last post by:
Hi everyone! I'm sure my problem is pretty easy to solve but I've been working on it for a long and my my brain is not working correctly anymore. I'm working with an AS400 and I mhave to do an...
5
by: CindySue | last post by:
Hello, I'm so stuck and this seems like it should be so simple. I have three tables, called Auction Items, Party #1 and Party #2. A bidder number may appear in one, two or all three of them....
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
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...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
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...
0
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...

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.