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

How to query users without orders in Mysql?

WBOY
WBOYOriginal
2016-10-11 14:23:112632browse

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

Statement:
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