当前位置:网站首页>Using method and de duplication of distinct() in laravel
Using method and de duplication of distinct() in laravel
2022-06-29 08:10:00 【Know the black and accept the white】
Read the directory
This paper
laravel in distinct( ) How to use and de duplication , MySQL Usually use GROUPBY ( It is essentially a sort action ) complete DISTINCT operation , If DISTINCT Operation and ORDERBY Operation combination use , Temporary tables are often used , This will affect performance , In some cases , MySQL You can use index optimization DISTINCT operation , But it needs to be learned and used flexibly .
One 、laravel5 How do you use it? distinct
laravel5 Use distinct It's simple , The official has offered to use distinct Method allows you to force a lookup to return a non repeating result :
$users = DB::table('users')->distinct()->get();
However, the code provided by the government cannot find and return non repeated results , We need to specify the following fields :
$users=DB::table('users')->select('name')->distinct()->get();
Two 、 how select Multiple fields
If you want to distinct Multiple fields , Can be in select Add field name to ;
But be careful , When select Multiple fields , Representative needs status And name All the same will be excluded .
$users=DB::table('users')->select('status','name')->distinct()->get();
This is it. laravel in distinct A summary of the methods used , If you want to retrieve data from a database , have access to GROUPBY Method .
边栏推荐
- What are the constraints in MySQL? (instance verification)
- qtcreator设置字符集
- Time operation - time format conversion
- Codeforces Round #799 (Div. 4)
- php 清除多维数组里面的空值
- Should product managers learn from ink knife or Axure?
- Qtcreator set character set
- Embedded product anti-theft version
- Django - installing mysqlclient error: mysqlclient 1.4.0 or newer is required; you have 0.9.3
- 为什么两个执行很快的SQL,union之后特别慢
猜你喜欢

Should product managers learn from ink knife or Axure?

Code:: blocks code formatting shortcuts
![[repair collection function, update login interface] knowledge payment applet, blog applet, full version open source code, resource realization applet, with 299 whole station resource data](/img/77/328bd10e97d1d78708464c5d59153a.png)
[repair collection function, update login interface] knowledge payment applet, blog applet, full version open source code, resource realization applet, with 299 whole station resource data
![[eye of depth Wu Enda's fourth operation class] summary of multiple linear regression with multiple variables](/img/51/581be1bdfe7cc97193ff68d3ec5d22.png)
[eye of depth Wu Enda's fourth operation class] summary of multiple linear regression with multiple variables

jsp学习部分

Vulnhub's DC8 target

SizeBalanceTree

PostgreSQL installation: the database cluster initialization failed, stack hbuilder installation

【深度之眼吴恩达第四期作业班】多元线性回归Linear Regression with multiple variables总结

MongoDB-使用mongo/mongosh命令行连接数据库
随机推荐
Basic syntax - bit operation
Protobuf 二进制文件学习及解析
SQL Server 2008 publish and subscribe to SQL Server 2017 pit avoidance Guide
Linear regression with one variable
Vulnhub's dc7 target
Basics - syntax standards (ANSI C, ISO C, GNU C)
[repair collection function, update login interface] knowledge payment applet, blog applet, full version open source code, resource realization applet, with 299 whole station resource data
MongoDB-使用mongo/mongosh命令行连接数据库
Verilog初体验
Pointer reference array element
Common MySQL errors and solutions summarized painstakingly (I)
从Nacos客户端谈Nacos配置中心
Codeforces Round #799 (Div. 4)
Embedded product anti-theft version
Handle series - install spotbugs and use them quickly
声波通讯 - 流式数据处理 - 窗口对齐
Robotframework learning notes: introduction to robot framework and browserlibrary (playwright)
Behaviortree in ros2
Oracle batch insert data - insert ethnic data
SQL SERVER 2008 发布订阅到SQL Server 2017避坑指南