开发者

syntax to get min from two tables

开发者 https://www.devze.com 2023-01-23 12:28 出处:网络
i have two different tables table1 - property ================= id,name, address, city state, zip t开发者_如何转开发able2 - floorvalue

i have two different tables

table1 - property
=================

id,name, address, city state, zip

t开发者_如何转开发able2 - floorvalue
===================

id, rentmin, rentmax, bedrooms, bathrooms

i need a query to fetch min rent values from the two tables, the current below query getting for eg two records with all the values like property id, name, city, state and then floor id, rmin, rmax etc. but i need the first minimum rent if i get two or more records of the same id.

query i have :

select
  p.id,
  p.name,
  p.address,
  p.city,
  p.state,
  p.zip,
  f.id,
  f.rmin,
  f.rmax,
  f.bedrooms,
  f.bathrooms 
from property as p, floorvalue as f 
where p.city = 'losangeles' and p.state = 'ca' and p.id = f.id


SELECT *
FROM property AS p, floorvalue AS f
WHERE p.id = f.id
ORDER BY f.rentmin
LIMIT 1

this will show the values related to the apartment whose minimum rent is minimal among tables. i hope this is what you need.


... AND f.rentmin = (select min(rentmin) from floorvalue f2, property p2 where ... your condition)

it could be written in a single select thouhg.

0

精彩评论

暂无评论...
验证码 换一张
取 消