In SQL, why do subqueries have to be followed by comparators?

Updated on society 2024-05-09
14 answers
  1. Anonymous users2024-02-09

    Who said it wrong???

    select top 1 * from test where name=(select max(name) from test)

    Or: select top 1 * from test where (select max(name) from test)=name

    It's all running!

    Actually, that mistake of yours is;

    Msg 512, Level 16, State 1, Line 2.

    The subquery returns more than one value. When the subquery is followed by =, !=, <, =, >, =, or when the subquery is used as an expression, this is not allowed.

    This is not a problem with subqueries!

    select top 1 * from test where name=(select name from test)

    name= should be a result, not a result set!

    So it can't be compared!

    If you want to do that, you can do that.

    select top 1 * from test where name=(select top 1 name from test)

    Or. select top 1 * from test where name=(select min(name) from test)

    This sentence is the result you want to achieve:

    select sno, sname, sdept

    from student

    where sdept in (select sdept

    from student

    where sname='Liu Chen')

  2. Anonymous users2024-02-08

    select sno, sname, sdeptfrom student

    where sdept in (select sdeptfrom student

    where sname='Liu Chen')

    That's right...

  3. Anonymous users2024-02-07

    Uh, buddy, first of all, does your table have a primary and foreign key relationship? Secondly, you have to explain what fields are in the household table and the person table. Eggplant pomace digging.

    The table is as follows: Hukou Verification Form (H) Person Form (P).

    NUB Account Number PID ID Number.

    address name name.

    state indicates the state relationship of the family relationship.

    nub account number.

    introduction.

    state state.

    Check your name, ID number, family relationship, head of household, and address.

    select ,,nvl((select from p p1 where like "It's the head of the household"),null) huzhuname,from p,h

    where ;

    nvl(old,new) returns old if there is an old value; Otherwise, the sub-query statement above new is returned.

    select from p p1 where like "It's the head of the household"

    It is the first to find out the name of the person who is the head of the household, and the specific conditions are determined by themselves (——

  4. Anonymous users2024-02-06

    The correct solution of simenyu.

    It is definitely not possible to use in directly, and the courses that are less than the students S2 electives will also be listed and used not exists, which I can't understand.

    This paragraph: select * from sc as sc2where

    AND is the same course selection information as the student's S2 elective courses.

    This paragraph: select * from sc as sc1where's2'

    and not exists

    select * from sc as sc2where

    and If there is the same information as the S2 course selection, the result is empty.

    If there is no information that is the same as that of S2, the information of S2 is found.

    The last overall paragraph:

    select sno,sname

    form s

    where not exists

    select * from sc as sc1where 's2'

    and not exists

    select * from sc as sc2where

    and If there is the same information as the S2 course selection, all the student number and name information of the result will be found.

    If the same information as the S2 course selection does not exist, the result is empty.

    It doesn't fit the topic at all. I don't know if I misunderstood.

  5. Anonymous users2024-02-05

    List all the courses taken by S2 students, list the names of courses taken by other students, and then join.

  6. Anonymous users2024-02-04

    Is it good that the data types don't match? select idd from dbo.Table 2 where city in (select ID from dbo.)

    Table 1 where name='Beijing'I can do that too. tested, city is of type nchar and id is of type int.

    Look at the other question you asked. I've already explained it.

  7. Anonymous users2024-02-03

    select b from bb where tb in (select a from aa where cc=1)

    The next one you select a from aa where cc=1 is looking for a

    And the condition you are looking for in front of you is TB, how can TB go to the collection of A to find it? Of course I can't find it!

  8. Anonymous users2024-02-02

    I can't get results when I use it like this.

    In the end, you can only do it with the left connection.

  9. Anonymous users2024-02-01

    Is there 200,300,400 data in tb, what type is tb, is it char type, and see if there are spaces in the back.

    See your other question: Is your 200, 300, 400 a lump sum or 3?

  10. Anonymous users2024-01-31

    First of all, you use TB IN (subquery), but you need to make sure that in the subquery, A found in A matches the type of TB, and in the TB column in Table BB, there are records that meet the corresponding data conditions that can be queried out from A, so that the data can be found from BB.

  11. Anonymous users2024-01-30

    SQL2000 does not support top (100*1), and SQL2000 should be changed to dynamic.

    declare @s nvarchar(2000)set @s='select top 100 * from a where id not in (select top ('+rtrim(100*1)+') id from awhere userid=8479) and userid =8479'

    exec (@s)

  12. Anonymous users2024-01-29

    It's a table

    A table has two aliases, which means two 'tables'

    In fact, you can query two tables with the same name, structure, and data.

    --You first understand the meaning of this statement, this statement is to query the record of the average value of advance greater than advance, a table cannot compare itself, then you need to make a mirror table, compare, so take different aliases to distinguish them.

    To use a very apt analogy:

    If you ask you whether you are handsome or not, but you don't know what other people look like, and you don't know what you look like, you don't know whether you are handsome or not, then you are given a mirror, and you see the mirror in the mirror and say that this guy is very pleasing to the eye, which makes a self-connection (comparison with yourself), and if there is a very ugly person next to you at this time, you wonder why there is such an ugly person, and this makes an external connection (comparison with other tables).

    For example, if it is inappropriate, the landlord will experience it himself, and he will understand it if he uses it more.

  13. Anonymous users2024-01-28

    A and b stand for the same table, which has a noun called self-joining.

    Study hard.

    You understand the meaning of this query statement.

    If you query the tilte, type, and advance fields in the title table, the total advance fields in the title table must be greater than the average value of the same type in the table.

  14. Anonymous users2024-01-27

    Here you might as well understand them as two identical tables, and the connection between the two tables can be understood.

Related questions
7 answers2024-05-09

In fact, there is no certain thing, and there are those who do not get married. But it is easy to drift away from the mainstream of society. >>>More

5 answers2024-05-09

Never underestimate the power of the torrent of the times!

7 answers2024-05-09

After makeup, remove makeup to prevent clogged pores and cause **enlarged pores and acne Lip makeup remover prevents melanin precipitation, causing the color of the lips to darken Without makeup, if you are kind to yourself, you should also remove makeup, and remove the dirt on your face for a day After removing makeup, it is best to wash the facial cleanser and then wash it, do a second cleansing, and clean it more thoroughly. Look

10 answers2024-05-09

The sense of ritual is very important, because there is a lack of a sense of ritual, so we live simply and roughly. So life is boring and uninteresting. >>>More

7 answers2024-05-09

Hello, I think marriage is a commitment from two people who love each other to each other, to give their lives to each other, to have each other in legal form, to create a happy and happy family together, and to support each other through life. >>>More