Tables:
user(id,auth,confirmed,policyagreed,username,password,idnumber,firstname,lastname,email,phone etc..)
user_info_data(id,userid,fieldid,data)
role(id,name,shortname,description,sortorder)
role_assignments(id,roleid,contextid,userid...)
context(id,contextlevel,instanceid,path,depth)
First Select Statement: Pulls all the info I need EXCEPT the `data` field where fieldid='15'
SELECT user.firstname AS Firstname, user.lastname AS Lastname, user.email AS Email, course.fullname AS Course, role.name AS Role FROM user, course, role, role_assignments AS asg INNER JOIN context AS context ON asg.contextid=context.id WHERE context.contextlevel = 50 AND role.id=asg.roleid AND user.id=asg.userid AND context.instanceid=course.id
Second Select Statement: Pulls the info I need but Course is unknown
SELECT user.firstname AS 'First Name', user.lastname AS 'Last Name', user.email AS 'Email', user_info_data.data AS 'IBCLC Certified' FROM user, user_info_data WHERE user.id = user_info_data.userid AND fieldid = '15'
Attempt at combining the 2:
SELECT user.firstname AS Firstname,
user.lastname AS Lastname,
user.email AS Email,
course.fullname AS Course,
role.name AS Role,
user_info_data.data AS 'IBCLC Certified'
FROM user,
course,
role,
role_assignments AS asg
INNER JOIN context AS context ON asg.contextid=context.id
INNER JOIN user_info_data ON user.id = user_info_data.userid
AND fieldid = '15'
WHERE context.contextlevel = 50
AND role.id=asg.roleid
AND user.id=asg.userid
AND context.instanceid=course.id
PHPmyadmin gives me this error when I attempt to run the query. #1054 - Unknown column 'user.id' in 'on clause'. I don't know if the order matters or not? Because the column exists(See attached). Any help is greatly appreciated.
Edit:
If that doesn't work, is it possible to select from a select statement? Something like:
SELECT * FROM (SELECT user.id,user.firstname AS Firstname, user.lastname AS Lastname, user.email AS Email, course.fullname AS Course, role.name AS Role FROM user, course, role, role_assignments AS asg INNER JOIN context AS context ON asg.contextid=context.id WHERE context.contextlevel = 50 AND role.id=asg.roleid AND user.id=asg.userid AND context.instanceid=course.id) AS userInfo INNER JOIN user_info_data ON userInfo.id = user_info_data.userid WHERE user_info_data.fieldid = '15';
Attached image(s)
This post has been edited by JonQCoder: 18 July 2012 - 09:40 AM

New Topic/Question
Reply


MultiQuote





|