Skip to main content
Clarify response.
Source Link
BillThor
  • 4.5k
  • 19
  • 12

In my experience, I have rarely developed code where a string constant is added to the result set. The proposed solution doesn't make sense to me. I would be highly suspicious of the code quality of a system that did this. Looking at this example I would code it as follows.

first_name  last_name  dept_code
----------- ---------- ---------
Fred        Flintstone 1
Barney      Rubble     1
Wilma       Flintstone 2

dept_code dept_name
--------- -------------------
1         ROCKS
2         FACEPALMING_AT_FRED

SELECT first_name, last_name, dept_name, 'BEDROCK' AS hometown
FROM characters c 
JOIN departments d ON (c.dept_code = d.dept_code )

I would forget his approach after this exercise. For it to work you would need a table or column for each constant or an update before each query. I would hope at some point an address table would be added from which hometown could be selected using an appropriate join.

In my experience, I have rarely developed code where a string constant is added to the result set. The proposed solution doesn't make sense to me. I would be highly suspicious of the code quality of a system that did this. Looking at this example I would code it as follows.

first_name  last_name  dept_code
----------- ---------- ---------
Fred        Flintstone 1
Barney      Rubble     1
Wilma       Flintstone 2

dept_code dept_name
--------- -------------------
1         ROCKS
2         FACEPALMING_AT_FRED

SELECT first_name, last_name, dept_name, 'BEDROCK' AS hometown
FROM characters c 
JOIN departments d ON (c.dept_code = d.dept_code )

I would forget his approach after this exercise. For it to work you would need a table for each constant or an update before each query. I would hope at some point an address table would be added from which hometown could be selected using an appropriate join.

In my experience, I have rarely developed code where a string constant is added to the result set. The proposed solution doesn't make sense to me. I would be highly suspicious of the code quality of a system that did this. Looking at this example I would code it as follows.

first_name  last_name  dept_code
----------- ---------- ---------
Fred        Flintstone 1
Barney      Rubble     1
Wilma       Flintstone 2

dept_code dept_name
--------- -------------------
1         ROCKS
2         FACEPALMING_AT_FRED

SELECT first_name, last_name, dept_name, 'BEDROCK' AS hometown
FROM characters c 
JOIN departments d ON (c.dept_code = d.dept_code )

I would forget his approach after this exercise. For it to work you would need a table or column for each constant or an update before each query. I would hope at some point an address table would be added from which hometown could be selected using an appropriate join.

Source Link
BillThor
  • 4.5k
  • 19
  • 12

In my experience, I have rarely developed code where a string constant is added to the result set. The proposed solution doesn't make sense to me. I would be highly suspicious of the code quality of a system that did this. Looking at this example I would code it as follows.

first_name  last_name  dept_code
----------- ---------- ---------
Fred        Flintstone 1
Barney      Rubble     1
Wilma       Flintstone 2

dept_code dept_name
--------- -------------------
1         ROCKS
2         FACEPALMING_AT_FRED

SELECT first_name, last_name, dept_name, 'BEDROCK' AS hometown
FROM characters c 
JOIN departments d ON (c.dept_code = d.dept_code )

I would forget his approach after this exercise. For it to work you would need a table for each constant or an update before each query. I would hope at some point an address table would be added from which hometown could be selected using an appropriate join.