简体   繁体   中英

Query to find districts with at least one value in assets table

This is my SQL query:

select count(*) from district

but i want to select only all districts that have at least 1 value in table assets stored. (can be more than 1)

so

select all districts that have at least 1 entry in assets

table assets: id name district_id

table district id name

How can I do that?

select count(*)
from district
where exists (
    select 1
    from assets
    where district_id = district.id
)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM