SQL query return data from multiple tables

前端 未结 6 956
被撕碎了的回忆
被撕碎了的回忆 2020-11-21 04:23

I would like to know the following:

  • how to get data from multiple tables in my database?
  • what types of methods are there to do this?
  • what are
6条回答
  •  走了就别回头了
    2020-11-21 05:18

    You can use the concept of multiple queries in the FROM keyword. Let me show you one example:

    SELECT DISTINCT e.id,e.name,d.name,lap.lappy LAPTOP_MAKE,c_loc.cnty COUNTY    
    FROM  (
              SELECT c.id cnty,l.name
              FROM   county c, location l
              WHERE  c.id=l.county_id AND l.end_Date IS NOT NULL
          ) c_loc, emp e 
          INNER JOIN dept d ON e.deptno =d.id
          LEFT JOIN 
          ( 
             SELECT l.id lappy, c.name cmpy
             FROM   laptop l, company c
             WHERE l.make = c.name
          ) lap ON e.cmpy_id=lap.cmpy
    

    You can use as many tables as you want to. Use outer joins and union where ever it's necessary, even inside table subqueries.

    That's a very easy method to involve as many as tables and fields.

提交回复
热议问题