How do I grab info from one table while still adding values?

ribre817

I'm working on a project and am trying to grab a key from another table while still grabbing from the values given. For example...

INSERT INTO Essay (student_ID, student_essay) VALUES (`Students.student_ID`, 'I WANNA BE THE VERY BEST');

I need to grab the student_ID from the Students table (otherwise the numbers will be off since student_ID is auto-increment), but I need to be able to insert the value of the essay.

Piyush Gupta

You need to use the Max(id) function.

You can use Max(id) function also it will return max id and you are using auto increment so offcorse it will return last id and that last id you can insert in 2nd table, like:

INSERT INTO Essay (student_ID, student_essay) 
       VALUES ((SELECT MAX(s_id) from Students), 'I WANNA BE THE VERY BEST');

here is S_id means you need to provide that id which you want to use in Students table.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How do I grab info from one table while still adding values?

From Dev

JSON has no identifiers, how do i grab info from it?

From Dev

How do I grab entries with common values for one element from a List<KeyValuePair<string, string>>?

From Dev

How do I grab the most recent price change from table

From Dev

Grab from table values

From Dev

how to write mysql query with join and still display partial info if a record from one table is deleted?

From Dev

How do I get all values present in one table, but only some from another table

From Dev

how do i grab orderId from this array?

From Dev

SQL: copy data from one table to another while adding additional columns of fixed values

From Dev

Grab one row from a table

From Dev

How do I insert a column of values from one table to another, non-matching schemas?

From Dev

How do i copy data from one table to another table?

From Dev

How do i copy data from one table to another table?

From Dev

How do I add NEW values in one table along with the values in another table to a third table?

From Dev

How do I add NEW values in one table along with the values in another table to a third table?

From Dev

How can I alter a table in Oracle while adding a column, which is of the same type as a column from a different table

From Dev

How do I concatenate two strings (one's a variable) while still being able to reuse one of the arguments (the variable)?

From Dev

How do I run a private pub server while still referencing packages from pub.dartlang.org?

From Dev

How do I forcibly ovewrite a local repo with changes from a remote repo while still preserving history?

From Dev

How do I remove the colon from this capturing group in PCRE, while still capturing correctly?

From Dev

How do I read in a specified number of characters from a file while still iterating through it?

From Dev

How do I forcibly ovewrite a local repo with changes from a remote repo while still preserving history?

From Dev

How do I pass values from one route to another in angular?

From Dev

how to join table that still retain all values from the main table

From Dev

How do I use a remote method in one model to return info from another model?

From Dev

How do I distributed a table using values from multiple columns?

From Dev

how do i get values from multidimensionnal table in javascript?

From Dev

How do I insert into a table values from two arrays in Postgres?

From Dev

How do I grab the selected radiobox value from a particular form?

Related Related

  1. 1

    How do I grab info from one table while still adding values?

  2. 2

    JSON has no identifiers, how do i grab info from it?

  3. 3

    How do I grab entries with common values for one element from a List<KeyValuePair<string, string>>?

  4. 4

    How do I grab the most recent price change from table

  5. 5

    Grab from table values

  6. 6

    how to write mysql query with join and still display partial info if a record from one table is deleted?

  7. 7

    How do I get all values present in one table, but only some from another table

  8. 8

    how do i grab orderId from this array?

  9. 9

    SQL: copy data from one table to another while adding additional columns of fixed values

  10. 10

    Grab one row from a table

  11. 11

    How do I insert a column of values from one table to another, non-matching schemas?

  12. 12

    How do i copy data from one table to another table?

  13. 13

    How do i copy data from one table to another table?

  14. 14

    How do I add NEW values in one table along with the values in another table to a third table?

  15. 15

    How do I add NEW values in one table along with the values in another table to a third table?

  16. 16

    How can I alter a table in Oracle while adding a column, which is of the same type as a column from a different table

  17. 17

    How do I concatenate two strings (one's a variable) while still being able to reuse one of the arguments (the variable)?

  18. 18

    How do I run a private pub server while still referencing packages from pub.dartlang.org?

  19. 19

    How do I forcibly ovewrite a local repo with changes from a remote repo while still preserving history?

  20. 20

    How do I remove the colon from this capturing group in PCRE, while still capturing correctly?

  21. 21

    How do I read in a specified number of characters from a file while still iterating through it?

  22. 22

    How do I forcibly ovewrite a local repo with changes from a remote repo while still preserving history?

  23. 23

    How do I pass values from one route to another in angular?

  24. 24

    how to join table that still retain all values from the main table

  25. 25

    How do I use a remote method in one model to return info from another model?

  26. 26

    How do I distributed a table using values from multiple columns?

  27. 27

    how do i get values from multidimensionnal table in javascript?

  28. 28

    How do I insert into a table values from two arrays in Postgres?

  29. 29

    How do I grab the selected radiobox value from a particular form?

HotTag

Archive