Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2011
    Posts
    9

    Unanswered: Select from multiple tables

    Hi All
    i have three tables.
    Table USERS Contains columns User_id and UserName
    Table DOMAIN Contains columns Domain_id and DomainName
    Table USER_DOMAIN Contains columns User_id, Domain_id, count, day, month, year

    i am looking to run a report that pulls its information from USER_DOMAIN but instead of displaying User_id, Domain_id, it returns the UserName and DomainName associated.

    The query to pull the info i need is very simple, where i am having problems is linking the user_id to the UserName and the Domain_id to the DomainName.

    Any help on this would be greatly appreciated.

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Code:
    SELECT users.username
         , domain.domainname
         , user_domain.count
         , user_domain.day
         , user_domain.month
         , user_domain.year
      FROM user_domain
    INNER
      JOIN users
        ON users.user_id = user_domain.user_id
    INNER
      JOIN domain
        ON domain.domain_id = user_domain.domain_id
    why separate columns for day, month, year? and what's the count column for?
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Jan 2011
    Posts
    9
    Thanks very much for your help

Posting Permissions

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