Question

I'm having a bit of trouble setting up a command for this, any tips? (MySQL) Update...

I'm having a bit of trouble setting up a command for this, any tips? (MySQL)

Update table room to set the value of column roomtype equal to the corresponding id value in the table roomtype. This requires a select * from roomtype; to see what the id value is for each roomDesc. For example, in my database

a. 1 | Critical

b. 2 | Private

c. 3 | Semi-Private

I think i need to use a Join but I'm not sure, any tips are appreciated !

0 0
Add a comment Improve this question Transcribed image text
Answer #1

From the question it shows that the table

room has attributes (roomtype, .. , ..) and

roomtype has attributes (id, roomDesc).

roomtype column in table `room` is supposed to store the "corresponding" id of roomtype , so it means that the table `room` also has another attribute specifying room description i.e. roomDesc. It is on the the basis of this that we will assign corresponding room ids in table `room`.

So the MySql query for this is:

UPDATE room SET roomtype = (SELECT roomtype.id FROM roomtype INNER JOIN room ON roomtype.roomDesc = room.roomDesc);

OR

UPDATE room SET roomtype = (SELECT roomtype.id FROM roomtype a INNER JOIN room b ON a.roomDesc = b.roomDesc);

OR

UPDATE room SET roomtype = (SELECT roomtype.id FROM roomtype INNER JOIN room USING (roomDesc));

when we don't use any join it is equivalent to an inner join.

Now let us understand the first syntax, then all the following are just equivalent syntax to know different ways of querying.

First,

SELECT roomtype.id FROM roomtype INNER JOIN room ON roomtype.roomDesc = room.roomDesc;

In both the tables where the roomDesc value matches, the entire row consisting of combined attributes of both the tables after the join are returned, (with the help of INNER JOIN)

(roomtype.id, room.roomtype, roomtype.roomDesc, .... ,,..)

from this row only roomtype.id is selected using SELECT roomtype.id ...

now this value is used to set room.roomtype essentially like

UPDATE room SET roomtype = "(the corresponding roomtype.id that was returned from above)";  

NOTE: WHERE clause was not used in this case of UPDATE statement, and we assume that the id corresponding to roomDesc in table roomtype table is one-one i.e. for eeach type of room description only one room id is there.

Add a comment
Know the answer?
Add Answer to:
I'm having a bit of trouble setting up a command for this, any tips? (MySQL) Update...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Creating a MySQL database and having trouble with this problem any help is appreciated. a. Tasks...

    Creating a MySQL database and having trouble with this problem any help is appreciated. a. Tasks Description 1. Update table room to set the value of column roomtype equal to the corresponding id value in the table roomtype. This requires a select * from roomtype: to see what the id value is for each room Dess. For example, in my database 1 | Critical b. 2 | Private c. 3 Semi-Private 2. Alter table room so that column roomType is...

  • i'm having trouble going backwards in reactions. if you have any tips please share. thank you!...

    i'm having trouble going backwards in reactions. if you have any tips please share. thank you! 3. For each reaction determine the reactant that lead to the formation of the indicated products. (3 points each) 3a. 1. KMnO4, warm 2. H, H20 & CO2 3b. 03, S(CH3)2 ОН 4. Molecule W has the molecular formula C8H14. When Molecule W is reacted first with BHz in tetrahydrofuran (THF) then treated with basic hydrogen peroxide the resulting products are an optically inactive...

  • this is an organic chemistry synthesis question, and I am having a little bit of trouble...

    this is an organic chemistry synthesis question, and I am having a little bit of trouble getting started. Any help with the mechanism would be appreciated! thanks! 2. The following reactions are from an article published by Masamune and Sharpless in Science, describing stereoselective synthesis of hexose sugars. a) The following conversion requires two reaction steps, the second one being protection of a diol as a cyclic acetal. Draw a reasonable mechanism for the first step of this reaction (NaOH,...

  • I'm having some trouble with this question. Not sure how to go about solving it. Any...

    I'm having some trouble with this question. Not sure how to go about solving it. Any help would be appreciated. Thanks. An object is made up of a disk (M=7.0kg, R=2.0m) and two point masses (m1=3.0kg and m2=4.0kg). The arrangement of the disk and the point masses are shown in the figure and the dimensions are d1=1.0m, d2=1.5m, d3=0.5m, d4=1.0m, and t=0.3m. A. What is the x-coordinate of the center of mass of the object? B. What is the z-coordinate...

  • Hello everyone! I am working on my assignment for C++ and I'm having a bit of...

    Hello everyone! I am working on my assignment for C++ and I'm having a bit of trouble on the value producing functions, I am creating a program wherein I have to input a value and I need to create a function called square value where in it will square the value I have input. I cannot seem to figure out this part. Here is the code that I have so far, and thank you for any help. I greatly appreciate...

  • Hi, I am having trouble solving the constructor, it requires to ArrayList marks to be a...

    Hi, I am having trouble solving the constructor, it requires to ArrayList marks to be a deep copy of the instance variable. I have also provided the J-Unit test I have been provided. import java.util.*; public class GradebookEntry { private String name; private int id; private ArrayList<Double> marks; /** * DO NOT MODIFY */ public String toString() { String result = name+" (ID "+id+")\t"; for(int i=0; i < marks.size(); i++) { /** * display every mark rounded off to two...

  • Overview: Database management plays an integral role in nearly every area of business. Databases house customer, accoun...

    Overview: Database management plays an integral role in nearly every area of business. Databases house customer, accounting, and employee data, and these different data sets must all be efficiently managed in order to make the data accessible. Companies rely on database engineers to ensure that their records are accurate, updated, and tracked in real time. This course covers structured query language (SQL) and how it can be used to manage database schemas, manipulate data, and analyze data. For your final...

  • I have two questions I'm having trouble understanding. I greatly appreciate any help you all can...

    I have two questions I'm having trouble understanding. I greatly appreciate any help you all can give me! I'm not great at physics so the more details the better. THANKS!!! In the RC circuit of Figure WG32.6, the emf of the AC source is given by 'E = Emax sin ω| t. The emf amplitude is Emax = 10 V, and the angular frequency is ω,-100 s-1 when the angular frequency is changed to a new value ω2, the time...

  • Hi, I'm having trouble understanding and answering this question and I do not have any solutions...

    Hi, I'm having trouble understanding and answering this question and I do not have any solutions to go off by. Please help? Integration of Metabolism/Signalling Question 3 Compare the metabolism of a 100 m sprinter, a 42.2 km marathon runner and a combined 226.3 km ironman triathlete. Your job is to determine the value or description of each of the parameters labelled 'A' to 'J'in Table I below, find its code number in Table II (Code Numbers for Question 3)...

  • Hey guys I am having trouble getting my table to work with a java GUI if...

    Hey guys I am having trouble getting my table to work with a java GUI if anything can take a look at my code and see where I am going wrong with lines 38-49 it would be greatly appreciated! Under the JTableSortingDemo class is where I am having erorrs in my code! Thanks! :) import java.awt.*; import java.awt.event.*; import java.util.*; import java.util.List; import javax.swing.*; public class JTableSortingDemo extends JFrame{ private JTable table; public JTableSortingDemo(){ super("This is basic sample for your...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT