Results 1 to 3 of 3

Thread: get a primary record from a linked table (resolved

  1. #1

    Thread Starter
    Still learning kebo's Avatar
    Join Date
    Apr 2004
    Location
    Gardnerville,nv
    Posts
    3,762

    Resolved get a primary record from a linked table (resolved

    I have a DB with the following 2 tables....

    EventsTable
    EventID -auto number primary key
    more fields...


    ScheduledEventsTable
    ID - foreign key pointing to a record in the Events table
    ScheduledDate - date the event should fire
    more fields....

    I am using the following command string to get all scheduled event between 2 dates and it works...

    Code:
    Dim cmdString As String = String.Format("SELECT * FROM ScheduledEvents WHERE EventDate BETWEEN #{0}# AND #{1}#", startdate, enddate)
    but what I really want is the record from the Events Table that corresponds with the forign key in the ScheduledEvents table.
    Can someone help me do this?
    I apologies if my terminology isn't right. Although I've be programming since there was dirt, I'm rather new to DB stuff.
    thanks
    kevin
    Last edited by kebo; Nov 16th, 2009 at 04:51 PM.
    Process control doesn't give you good quality, it gives you consistent quality.
    Good quality comes from consistently doing the right things.

    Vague general questions have vague general answers.
    A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.

    ______________________________
    Last edited by kebo : Now. Reason: superfluous typo's

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: get a primary record from a linked table

    When you ask SQL based questions please tell us the database system you are working with, because it usually makes a difference (in this particular case the difference is minor, but could still cause issues).


    To work with more than one table you use a Join, which could be like this:
    Code:
    SELECT Events.*
    FROM Events
    INNER JOIN ScheduledEvents ON (Events.EventID = ScheduledEvents.ID)
    WHERE ....
    If you only want particular fields from the Events table, you should specify them rather than using *

  3. #3

    Thread Starter
    Still learning kebo's Avatar
    Join Date
    Apr 2004
    Location
    Gardnerville,nv
    Posts
    3,762

    Re: get a primary record from a linked table

    thanks a bunch... I was close to it, but off by about 4.32 miles
    kevin
    Process control doesn't give you good quality, it gives you consistent quality.
    Good quality comes from consistently doing the right things.

    Vague general questions have vague general answers.
    A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.

    ______________________________
    Last edited by kebo : Now. Reason: superfluous typo's

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width