Results 1 to 3 of 3

Thread: [SQL] Help me with Joins!

  1. #1
    Guest
    Table Vendor consists of a Vendor ID (vendorid) and the Vendor (vendor). Table Type consists of the Type ID (typeid) and the Type (type).

    The equipment table consists of id, vendorid, typeid, partnum, details, cost, markup

    What I need is to query all records in Equipment and have the vendorid field filled in from the matching "vendor" record in the vendor table and have the typeid filled in from the matching "type" record in the type table.

    SELECT vendor.vendor as vendor, type.type as type, id, partnum, details, cost, markup from vendor, type, equipment where vendor.vendorid = equipment.vendorid and type.typeid = equipment.typeid.

    I know that SQL is incorrect but I hope you can understand what I want from reading it.

    p.s. this is against MySQL

  2. #2
    Lively Member
    Join Date
    Jul 2000
    Location
    Stockholm, Sweden
    Posts
    83
    I dont use MySQL but I am thinking of installing a Linux machine and MySQL. Do you access MySQL with VB ?

    I don't see any strange with you SQL.

    You could refrase it little. What error messge do you get ?

    Code:
    SELECT
     vendor.vendor,
     type.type,
     equipment.id,
     equipment.partnum,
     equipment.details,
     equipment.cost,
     equipment.markup
    FROM
     vendor,
     type,
     equipment
    WHERE
     vendor.vendorid = equipment.vendorid
    AND
     type.typeid = equipment.typeid.
    Yesterday, all my troubles seemed so far away...
    Help, I need somebody, Help...
    Now MCSD and still locking for intresting job in the south parts of Stockholm, Sweden.

  3. #3
    Guest

    Question Other join syntax

    AKA,

    You could try something like the following, which
    should do the same as the stuff you had before. Note that if any of the matching fields are null then the row will not be returned, if you want the rows anyway then you may want to use another type of join.

    I have never used MySQL but the code below should work on SQL Server and the syntax should be ANSI compliant, I think!

    SELECT
    vendor.vendor,
    type.type,
    equipment.id,
    equipment.partnum,
    equipment.details,
    equipment.cost,
    equipment.markup
    FROM vendor
    INNER JOIN type on vendor.vendorid = equipment.vendorid
    INNER JOIN equipment on equipment.typeid = type.typeid

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