Solved

mysql join

Posted on 2009-06-30
2
292 Views
Last Modified: 2012-05-07
hi
i want to join two tables together currently i am selecting from the code table

SELECT userip, datef, quiz, username, sum(category) as category, count(qid) as qid FROM codes group by quiz,username ORDER BY category
but i also wants to select fields from the enterused table where code and enterused table quiz value is the same
CREATE TABLE `enterused` (
  `id` int(10) NOT NULL auto_increment,
  `randomcode` varchar(100) NOT NULL,
  `category` varchar(50) NOT NULL,
  `quiz` varchar(100) NOT NULL,
  `datef` varchar(30) default NULL,
  `type` int(10) default NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=21 DEFAULT CHARSET=latin1 AUTO_INCREMENT=21 ;
0
Comment
Question by:mattibutt
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 60

Accepted Solution

by:
Kevin Cross earned 500 total points
ID: 24747316
If there is always a match or you only want rows that have both tables for data, use an INNER JOIN.

e.g.

SELECT c.username, e.type
FROM codes c
INNER JOIN enterused e ON e.quiz = c.quiz

If there may not be a value in enterused, then use LEFT OUTER JOIN.

e.g.

SELECT c.username, e.type
FROM codes c
LEFT OUTER JOIN enterused e ON e.quiz = c.quiz

When there is not a match, e.type in this example will be NULL.

If other way around, you can use RIGHT OUTER JOIN or just switch the order of the tables with LEFT OUTER JOIN.
0
 
LVL 11

Author Closing Comment

by:mattibutt
ID: 31598413
thanks buddy its good to hear from you after a while i did manage to do it
0

Featured Post

Save the day with this special offer from ATEN!

Save 30% on the CV211 using promo code EXPERTS30 now through April 30th. The ATEN CV211 connects a laptop directly to any server allowing you instant access to perform data maintenance and local operations, for quick troubleshooting, updating, service and repair.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question