查找2个select语句中是否存在重复项

时间:2020-11-11 07:23:05

标签: sql sql-server sql-server-2016

能否请您帮助我使用SQL语句来查找第一个Select语句和第二个Select语句中存在的重复名称。

例如: 我需要查找第1班或第3班是否有同名学生。

select firstname from College where classid = 1

第二个select语句是:

select firstname from College where classid in (2, 3)

如果任何名称都有匹配的出现,那么我想选择该记录。

3 个答案:

答案 0 :(得分:1)

通过将classid=1表达式与classid in (2,3)子句一起使用,例如{p>

GROUP BY
每当从每个聚合返回的两个结果都大于零时,

HAVING值就会在每个集合中重复。

Demo

答案 1 :(得分:1)

加入可能是一种选择

AutoCompleteTextField(
                            focusNode: pincodeFocus,
                            decoration: InputDecoration(
                              errorText: pincode.text == '' ? 'Null' : null,
                              border: InputBorder.none,
                              prefixIcon: Icon(Icons.home),
                              hintText: "Pincode",
                            ),
                            controller: pincode,
                            itemSubmitted: (item) {
                              setState(() {
                                pincode.text = item.toString();
                                textField.controller.text = item.toString();
                                print('item submitted' + item.toString());
                              });
                            },
                            key: key,
                            suggestions: suggestionList,
                            itemBuilder: (context, item) {
                              return Container(
                                padding: EdgeInsets.all(20.0),
                                child: Row(
                                  children: <Widget>[
                                    Text(
                                      item,
                                      style: TextStyle(color: Colors.black),
                                    )
                                  ],
                                ),
                              );
                            },
                            itemSorter: (a, b) {
                              return a.compareTo(b);
                            },
                            itemFilter: (item, query) {
                              return item
                                  .toLowerCase()
                                  .toString()
                                  .startsWith(query.toLowerCase());
                            },
                          ),

或者,您也可以尝试使用select a.firstname from ( select firstname from College where classid = 1 )a join ( select firstname from College where classid in(2,3) )b on a.firstname=b.firstname

exists

答案 2 :(得分:0)

一种非常简单的基于集合的方法是使用public async Task<IActionResult> Online([FromForm]CandidaturaAddModel model) { var formContent = new MultipartFormDataContent(); formContent.Add(new StringContent(model.Senha), "Senha"); formContent.Add(new StringContent(System.Text.Json.JsonSerializer.Serialize(model.AnoLectvo)), "AnoLectvo"); //... //for other properties, such as Email, Genero etc //... formContent.Add(new StreamContent(model.Foto.OpenReadStream()), "Foto", Path.GetFileName(model.Foto.FileName)); _httpClient.BaseAddress = new Uri("https://localhost:xxxx/"); var response = await _httpClient.PostAsync("/api/xxx/CandidaturaAdd", formContent); if (response.IsSuccessStatusCode) { //.... }

intersect
相关问题