MySQL query to find if a value of one column in one table is between two values in two columns on another table

JDA

Long title question, so my apologies for that! I have two tables, one is as follows:

Student Name         Grade
John Doe             96
John Foe             65
Dan Doe              76
Mary Doe             85

The other table, is as follows:

Grade Start      Grade End       Status
0                60              Bad Student
61               70              OK Student
71               80              Good Student
81               90              Great Student
91               100             Honor Student

I am trying to create a MySQL view that will pull the student's grade, and tell me the status of that student such as:

Student Name     Grade      Status
John Doe         90         Honor Student
John Foe         65         OK Student

So on and so forth. I can't think of a query that will give me that information. I'm at a complete loss with the query, any help?

SELECT student_name, student_grade from student_grade_table WHERE ???
Barmar

Use a join:

SELECT s.student_name, s.grade, g.status
FROM students AS s
JOIN grades as g ON s.grade BETWEEN g.grade_start AND g.grade_end

DEMO

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

PHP: two table in one query

From Dev

SQL Select two columns from one table translated by a column from another table

From Dev

Find two table where one table has redundant value

From Dev

Query to get values of one table which are not there in string column of another table, also less than a particular datetime value

From Dev

Check if a value in one table (X) is between the values in two columns in another table (Y) with R data.table

From Dev

Join two columns in one table to a column in another reference table

From Dev

Update two columns values in a table based on another column value in different table

From Dev

Mysql Query Join two table Order by one table column

From Dev

MySql query joining two table and get combine two row to be one

From Dev

updating one table with the value of another table and the two tables are in seperate database

From Dev

MYSQL join one colum from one table to two count() in another

From Dev

How to access one column of a table corresponding to two different columns of another table in mysql?

From Dev

PHP: two table in one query

From Dev

mysql two table with different record in one query

From Dev

Update multiple columns in one table based on values in another table in mysql

From Dev

Procedure to insert data from one column into two columns in another table

From Dev

Query to get values of one table which are not there in string column of another table, also less than a particular datetime value

From Dev

Inserting values of one column of a table into different columns of another table

From Dev

Join two columns in one table to a column in another reference table

From Dev

Set two values in one table based on sum of a column in another table

From Dev

How to split one column into two columns just by counting the characters and inserting them into another table via a SQL query?

From Dev

Taking ids from two rows of one MySQL table and entering those values in one row of another MySQL table using PHP

From Dev

MYSQL query - simple way to return all values from one column based on a DISTINCT value in another column in the same table?

From Dev

How to return data from two tables only when the column value in one table is same as another table using MySQL?

From Dev

Spotfire - Getting data from one table that falls between two dates in another table and adding to a calculated column

From Dev

How to add two mysql table columns to one column in datagridview?

From Dev

Need help MSSQL query to bring table with two columns into one showing unique value of field 1 and corresponding values in field 2 (in that order)?

From Dev

Two columns refer to one id in another table

From Dev

SQL Query to compare two columns with one column from another table (and get two values)

Related Related

  1. 1

    PHP: two table in one query

  2. 2

    SQL Select two columns from one table translated by a column from another table

  3. 3

    Find two table where one table has redundant value

  4. 4

    Query to get values of one table which are not there in string column of another table, also less than a particular datetime value

  5. 5

    Check if a value in one table (X) is between the values in two columns in another table (Y) with R data.table

  6. 6

    Join two columns in one table to a column in another reference table

  7. 7

    Update two columns values in a table based on another column value in different table

  8. 8

    Mysql Query Join two table Order by one table column

  9. 9

    MySql query joining two table and get combine two row to be one

  10. 10

    updating one table with the value of another table and the two tables are in seperate database

  11. 11

    MYSQL join one colum from one table to two count() in another

  12. 12

    How to access one column of a table corresponding to two different columns of another table in mysql?

  13. 13

    PHP: two table in one query

  14. 14

    mysql two table with different record in one query

  15. 15

    Update multiple columns in one table based on values in another table in mysql

  16. 16

    Procedure to insert data from one column into two columns in another table

  17. 17

    Query to get values of one table which are not there in string column of another table, also less than a particular datetime value

  18. 18

    Inserting values of one column of a table into different columns of another table

  19. 19

    Join two columns in one table to a column in another reference table

  20. 20

    Set two values in one table based on sum of a column in another table

  21. 21

    How to split one column into two columns just by counting the characters and inserting them into another table via a SQL query?

  22. 22

    Taking ids from two rows of one MySQL table and entering those values in one row of another MySQL table using PHP

  23. 23

    MYSQL query - simple way to return all values from one column based on a DISTINCT value in another column in the same table?

  24. 24

    How to return data from two tables only when the column value in one table is same as another table using MySQL?

  25. 25

    Spotfire - Getting data from one table that falls between two dates in another table and adding to a calculated column

  26. 26

    How to add two mysql table columns to one column in datagridview?

  27. 27

    Need help MSSQL query to bring table with two columns into one showing unique value of field 1 and corresponding values in field 2 (in that order)?

  28. 28

    Two columns refer to one id in another table

  29. 29

    SQL Query to compare two columns with one column from another table (and get two values)

HotTag

Archive