$question_text = $DB->get_record_sql("SELECT u.`id` AS url_id,u.`course`,u.`name`,u.`externalurl`,cm.`id`,cm.`section` FROM `mdl_url` u JOIN `mdl_course_modules` cm ON u.`id`=cm.`instance` WHERE cm.`course`='$cid' AND cm.`module`='21' AND cm.`section`='$chapter_id' AND u.id > $question_id ORDER BY u.id LIMIT 1");
What is the purpose of using the u. query in the above query?
CodePudding user response:
u is the alias of the table name. We often use alias to save time writing full table name. Especially when when query is complex, use of aliases is a good practice.
CodePudding user response:
I got the solution here 'u' is the short form of table mdl_url. we can call the long table name in short form by defining short names to our table for example, SELECT u.'name' FROM 'user' u
This scenario comes only when we have multiple tables and we need to combine both the tables.