skip to Main Content

I need to write a query which must include use of INNER JOIN, but did not manage to write it correctly.

In PhpMyAdmin, I created a database with two related tables of users:

Table #1 is called “Usertype” and has two columns:

1.typnum (auto increment)

2.typdsc – which has three types of values: Inactive, Guest and Webmaster

Table #2 is called “Users” and has five columns:

  1. usrnum
  2. usrlogin
  3. usrpassword
  4. usrrealname
  5. usrtyp (the foreign key I connected with typnum)

What I need to show is the following records of Guests and Webmasters: usrlogin, usrpassword, usrrealname and the name of their types (while using Inner Join for the last one).
In other words, I need to show records which are NOT ‘Inactive’, show what their types are instead and the rest of their values EXCEPT usrnum

This is the query I tried to write for this:

SELECT users.usrlogin,users.usrpassword,users.usrrealname AND user.usrtyp
FROM users 
WHERE usrtyp NOT IN 'Inavctive' AND INNER JOIN userstypes ON users.usrtyp = userstypes.typnum

Thank you in advance!

2

Answers


  1. Try this:

    SELECT u.usrlogin, u.usrpassword, u.usrrealname, ut.typdsc 
    FROM users u INNER JOIN userstypes ut
    ON u.usrtyp = ut.typnum
    WHERE ut.typdsc <> 'Inactive'
    
    Login or Signup to reply.
  2. order matters in sql where is last. Also remove the random AND

    SELECT users.usrlogin,users.usrpassword,users.usrrealname, userstypes.usrtyp
    FROM users 
    INNER JOIN userstypes ON users.usrtyp = userstypes.typnum
    WHERE usrtyp NOT IN ('Inavctive')
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search