Home > Backend Development > PHP Tutorial > How to query users without orders in Mysql?

How to query users without orders in Mysql?

WBOY
Release: 2016-10-11 14:23:11
Original
2642 people have browsed it

Suppose there is an Order table and a User table. How should I query all users who do not have orders in one statement?

Reply content:

Suppose there is an Order table and a User table. How should I query all users who do not have orders in one statement?

The fields of at least two tables must be given, and the relationship between them must be made clear...

select userid from user where userid not in (select distinct userid from order)
roughly like this

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template