[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.3

MySql query two tables from one table

Asked by groone in MySQL Server

Tags: MySQL

I have 3 mysql tables
dest
users
teachers

The dest table has the following columns
ID
USERID
UTYPE
USERMSG
ENTRYDATE

ID is an auto increment

USERID is a non unique column of auto increment ID's from users and teachers
UTYPE is a set "user", "teacher" and is the only thing that separates the entries since USERID is not unique.

This is my current query

SELECT
      dest.ID,
      dest.USERID,
      dest.UTYPE,
      dest.USERMSG,
      dest.ENTRYDATE ,
      if(jobbr.UTYPE = 'user', users.LOGIN, teachers.LOGIN) AS LOGIN
FROM
      dest, users, teachers
WHERE
      ((dest.USERID = users.ID) AND (dest.UTYPE = 'user'))
OR
      ((dest.USERID = teachers.ID) AND (dest.UTYPE = 'teacher'))
ORDER BY
      dest.ENTRYDATE
DESC LIMIT 0,30

And it brings up

ID       USERID       UTYPE       USERMSG       LOGIN
73       24       teacher       This is an teacher test       groone
73       24       teacher       This is an teacher test       groone
72       24       teacher       test       groone
72       24       teacher       test       groone
72       24       teacher       test       groone
71       73       user       Trying to add teacher options now       groone
56       73       user       I have the recent tab working, not sure how becaus...       groone
55       76       user       howdy everyone!       2008-04-22 23:54:29       test
49       73       user       cookies seem to work well now back and forth to th...       groone
44       73       user       Going to be adding teachers now.  They will be a ...       groone
39       75       user       Curabitur tellus. Phasellus tellus turpis, iaculis...       grump
38       75       user       Donec a ante. Donec neque purus, adipiscing id, el...       grump

When it should only bring up:

ID       USERID       UTYPE       USERMSG       LOGIN
73       24       teacher       This is an teacher test       groone
72       24       teacher       test       groone
71       73       user       Trying to add teacher options now       groone
56       73       user       I have the recent tab working, not sure how becaus...       groone
55       76       user       howdy everyone!       test
49       73       user       cookies seem to work well now back and forth to th...       groone
44       73       user       Going to be adding teachers now.  They will be a ...       groone
39       75       user       Curabitur tellus. Phasellus tellus turpis, iaculis...       grump
38       75       user       Donec a ante. Donec neque purus, adipiscing id, el...       grump

As you can see, when it brings up teacher, it replicates the same number of records that are within user. I took out the entry columns so results would show on one line
[+][-]04/28/08 12:12 PM, ID: 21456745Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zone: MySQL Server
Tags: MySQL
Sign Up Now!
Solution Provided By: andygarratt
Participating Experts: 2
Solution Grade: A
 
 
Loading Advertisement...
20091111-EE-VQP-89 / EE_QW_2_20070628