e*****u 发帖数: 67 | 1 自學SQL query, 學到這個例子:
SELECT id, first_name
FROM student_details
WHERE first_name IN (SELECT first_name
FROM student_details
WHERE subject= 'Science');
source: http://beginner-sql-tutorial.com/sql-subquery.htm
為什麽不簡單這樣做, i,e why not -
SELECT id, first_name
FROM student_details
where subject= 'Science'; | d*******y 发帖数: 1154 | 2 这俩query不一样
第一个query是把所有选过science的学生记录都调出来。
比如一个学生选了science, math, art,那么他的三个记录都会被调出来。
第二个query不能调出math和art
【在 e*****u 的大作中提到】 : 自學SQL query, 學到這個例子: : SELECT id, first_name : FROM student_details : WHERE first_name IN (SELECT first_name : FROM student_details : WHERE subject= 'Science'); : source: http://beginner-sql-tutorial.com/sql-subquery.htm : 為什麽不簡單這樣做, i,e why not - : SELECT id, first_name : FROM student_details
| s******r 发帖数: 1524 | 3 For instance,
first_name subject
smith science
smith arts
the query will pick up both. your query will only pick up the first one.
【在 e*****u 的大作中提到】 : 自學SQL query, 學到這個例子: : SELECT id, first_name : FROM student_details : WHERE first_name IN (SELECT first_name : FROM student_details : WHERE subject= 'Science'); : source: http://beginner-sql-tutorial.com/sql-subquery.htm : 為什麽不簡單這樣做, i,e why not - : SELECT id, first_name : FROM student_details
| a******n 发帖数: 11246 | 4 其实还是楼主那句query更make sense。
比如
id first_name last_name subject
1 smith john science
2 smith david arts
书里那句会把两个人都选进来。。。
【在 s******r 的大作中提到】 : For instance, : first_name subject : smith science : smith arts : the query will pick up both. your query will only pick up the first one.
|
|