I have created 2 tables in MySQL [items, orderList], the foreign key id in orderlist references the primary key id in items. Now I want to take all columns{id, name, price (in Items), and quantity (in orderList)} from 2 tables in Java, how can I show id once because when I query data it shows id from both tables?
-
Show what you have tried ?Atul Sharma– Atul Sharma2018-07-14 05:44:26 +00:00Commented Jul 14, 2018 at 5:44
-
what you tried exactly? you can do that with join queriesRamana V V K– Ramana V V K2018-07-14 05:46:17 +00:00Commented Jul 14, 2018 at 5:46
Add a comment
|
2 Answers
You can do with join queries, try the below query and select the fields whatever you want from two tables
SELECT items.id, items.name, items.price, orderList.quantity
FROM items INNER JOIN orderList ON items.id = orderList.id
2 Comments
Ramana V V K
is total price column existing in the table? then only you can use the update query to set the value
In order to fetch the data only once, you need to mention where it should come from. You can try the following:
SELECT I.ID, I.NAME, I.PRICE, O.QUANTITY FROM ORDERLIST O, ITEMS I WHERE I.ID = O.ID
Here we have given aliases to both the tables and we have mentioned that the ID column will be picked from the ITEMS table.