1 to Many Query (1 Viewer)

Surka

IT dude
Local time
Today, 02:05
Joined
Aug 5, 2013
Messages
41
I am migrating my application from VBA to VB.Net, and a new problem appears.

Access DB tables and fields:

  • Users: ID_User, UserName
  • Devices: ID_User, Device, WarrantyEnd
With a 1 to Many Relationship, by ID_User on both tables.

Example, of table and relationship:

table Devices:
ID_User--Device---WarrantyEnd
2----------Laptop---2016
2----------Monitor--2016
3----------Laptop---2016

table Users:
ID_User--UserName
2----------AAA
3----------BBB


I need to fill a list, and show 3 columns: UserName, Device and WarrantyEnd.

How should the query be in order to get those results? It needs to get the UserName using the relationship.

Here is what I know:
Code:
SELECT Users.ID_User, Devices.Device, Devices.WarrantyEnd FROM Users RIGHT JOIN Devices
Thanks
 

JHB

Have been here a while
Local time
Today, 06:05
Joined
Jun 17, 2012
Messages
7,732
Use the QBE widows when you create queries, (then you'll get the result served on a tray). :)

SELECT Users.UserName, Devices.Device, Devices.WarrantyEnd
FROM Users RIGHT JOIN Devices ON Users.ID_User = Devices.ID_User;
 

jdraw

Super Moderator
Staff member
Local time
Today, 01:05
Joined
Jan 23, 2006
Messages
15,364
Why do you use a Right JOin vs an Inner Join?

I could see Right Join if you want everything from Devices (unassigned).
 

Users who are viewing this thread

Top Bottom