how to get details from multiple tables?

前端 未结 2 1823
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-16 14:12

In MySql database have AM_COURSE table in that

cId      CourseName   course_desc
  101          java        sometext...
  102          mysql             


        
2条回答
  •  悲哀的现实
    2021-01-16 14:29

    The INNER JOIN keyword returns rows when there is at least one match in both tables.

    MySQL INNER JOIN clause

    The MySQL INNER JOIN clause matches rows in one table with rows in other tables and allows you to query rows that that contain columns from both tables.

    The MySQL INNER JOIN clause an optional part of the SELECT statement. It appears immediately after the FROM clause.

    Before using MySQL INNER JOIN clause, you have to specify the following criteria:

    First, you have to specify the main table that appears in the FROM clause. Second, you need to specify the tables that you want to join with the main table, which appear in the INNER JOIN clause. Theoretically, you can join a table with many tables. However, for a better query performance, you should limit the number of tables to join. Third, you need to specify the join condition or join predicate. The join condition appears after the keyword ON of the INNER JOIN clause. The join condition is the rule for matching rows between the main table and the other tables.

    Example

    SELECT  c.cid, c.course_desc, user.name FROM AM_COURSE c
    INNER JOIN AM_INTER inter on inter.cid = c.cid
    INNER JOIN AM_USER user on user.uid = inter.uid
    INNER JOIN AM_TIMETABLE tt ON inter.cid = tt.UserId
    WHERE c.Name = 'coursename' AND tt.Date_Time BETWEEN '2011-08-12' AND '2012-08-12'
    

提交回复
热议问题