SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: Inner join

  1. #1
    SitePoint Enthusiast EspenA's Avatar
    Join Date
    May 2004
    Location
    Norway, Oslo
    Posts
    85
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Inner join

    Hi,

    I have some small problems with a SQL Query.

    ebanews_users:
    id | username | first_name | last_name | userlevel

    ebanews_userlevels:
    name | level

    I want to display all users that exists in the ebanews_users-table and the userlevel that belongs to each user. The "userlevel" column in the user-table is an id that's "connected" to the "level" in the userlevel-table. I want do display it like this:

    id | username | first_name | last_name | userlevel
    65 | EspenA | Espen | Andersson | Administrator

    I have created three different userlevels: Administrator, Superuser and User. I tried this SQL Query:

    Code:
    SELECT ebanews_user.id, ebanews_user.username, ebanews_user.first_name, ebanews_user.last_name, ebanews_userlevels.name 
        FROM ebanews_user 
        INNER JOIN ebanews_userlevels 
        ON ebanews_user.id = ebanews_userlevels.id
        ORDER BY id
    But it stops after three rows (when all the different userlevels are displayed).

    Can anybody help me?

  2. #2
    Original Gangster silver trophy Thing's Avatar
    Join Date
    Oct 2000
    Location
    Philadelphia, PA
    Posts
    4,708
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    You want to join based on their level. This will display all members who actually have a level. If they do not, then they will not display.
    Code:
    SELECT ebanews_user.id, ebanews_user.username, 
    ebanews_user.first_name, ebanews_user.last_name, 
    ebanews_userlevels.name 
    	FROM ebanews_user 
    	INNER JOIN ebanews_userlevels 
    	ON ebanews_user.userlevel = ebanews_userlevels.level
    	ORDER BY id

  3. #3
    SitePoint Enthusiast EspenA's Avatar
    Join Date
    May 2004
    Location
    Norway, Oslo
    Posts
    85
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Mongoloid,

    Ah, thanks! It works great


Bookmarks

Posting Permissions

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