load data from 5 different tables

r4k35h

Member
Joined
Sep 4, 2006
Messages
20
Programming Experience
Beginner
HI,

I need some help in vb.net and if anyone can help please do it right here don't link me to another site as my connection is very very slow (8kbps)
In “Vb.Net 2005” I want to load data from 5 different tables to a table/datagridview in the form;
This is how the table is formed in the db (ORACLE):
Table1:
Unique ID
Data1
UID001
XYZ
UID002
ABC

Table2:
Unique ID(not unique)
Data2
UID001
FAT
UID002
RAT

Table3:
Unique ID(not unique)
Data3
UID001
9090
UID001
1010
UID002
2020
UID003
3030
UID004
1234



Now I want vb.net to display it as:
Unique ID
Data1
Data2
Data3(need to show only last entry for that ID)
UID001
XYZ
FAT
1010
UID002
ABC
RAT
1234


PLEASE REPLY,THX
 
This is not a VB question but rather an SQL question. To get data from a database in VB you simply execute a query and it will return the appropriate data. What data gets returned is determined by your SQL code, which has nothing to do with VB.

If you want to get data from multiple tables you use an SQL join, e.g.
VB.NET:
SELECT
    c.ID,
    p.Name AS ParentName,
    c.Name
FROM
    Child c
INNER JOIN
    Parent p
ON
    c.ParentID = p.ID
That will retrieve every record from the Child table and return its ID and Name value, plus the Name value from the Parent table that corresponds to that Child's ParentID value. This query creates a result set, which you can then join with other tables or result sets, e.g.
VB.NET:
SELECT
    c.ID,
    gp.Name AS GrandparentName,
    p.Name AS ParentName,
    c.Name
FROM
       (Child c
    INNER JOIN
        Parent p
    ON
        c.ParentID = p.ID)
INNER JOIN
    Grandparent gp
ON
    p.GrandparentID = gp.ID
 
Does the syntax of enclosing part of the join block in brackets actually work in oracle? I would have written this:

VB.NET:
[LEFT]SELECT
    c.ID,
    gp.Name AS GrandparentName,
    p.Name AS ParentName,
    c.Name
FROM
    Child c
    INNER JOIN
    Parent p
    ON
        c.ParentID = p.ID
    INNER JOIN
    Grandparent gp
    ON
        p.GrandparentID = gp.ID

While I've used brackets to demark a subquery, i've never used/seen them purely to encapsulate a join.. Just double checking..[/LEFT]
 
Never tried it in Oracle but it works fine in Access or SQL Server. Just like in mathematics, sometimes it's a good idea to use parentheses for clarity in places where it isn't strictly required. I've not written many stored procedures and never for anyone else so my SQL formatting may be a little unconventional. Works for me though.
 
Back
Top