sql statement to select all from another table [closed]












-4














lists table



id user_id list_name
1 1 test
2 1 test2


items table



id list_id item_name price_item item_checked
1 1 apple 2 0
2 2 orange 2 0


result should be



id item_name price_item item_checked
1 Apple 2 0


How would i accomplish to select all from list 1










share|improve this question















closed as too broad by Barmar, Funk Forty Niner, Nick, Shadow, halfelf Nov 21 at 2:30


Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.











  • 3




    Hint: JOIN, WHERE.
    – Gordon Linoff
    Nov 20 at 22:30






  • 3




    what did you try so far?
    – mdem7
    Nov 20 at 22:32
















-4














lists table



id user_id list_name
1 1 test
2 1 test2


items table



id list_id item_name price_item item_checked
1 1 apple 2 0
2 2 orange 2 0


result should be



id item_name price_item item_checked
1 Apple 2 0


How would i accomplish to select all from list 1










share|improve this question















closed as too broad by Barmar, Funk Forty Niner, Nick, Shadow, halfelf Nov 21 at 2:30


Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.











  • 3




    Hint: JOIN, WHERE.
    – Gordon Linoff
    Nov 20 at 22:30






  • 3




    what did you try so far?
    – mdem7
    Nov 20 at 22:32














-4












-4








-4







lists table



id user_id list_name
1 1 test
2 1 test2


items table



id list_id item_name price_item item_checked
1 1 apple 2 0
2 2 orange 2 0


result should be



id item_name price_item item_checked
1 Apple 2 0


How would i accomplish to select all from list 1










share|improve this question















lists table



id user_id list_name
1 1 test
2 1 test2


items table



id list_id item_name price_item item_checked
1 1 apple 2 0
2 2 orange 2 0


result should be



id item_name price_item item_checked
1 Apple 2 0


How would i accomplish to select all from list 1







mysql sql






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 20 at 23:22









Shadow

25.5k92743




25.5k92743










asked Nov 20 at 22:27









Midorikawa

15




15




closed as too broad by Barmar, Funk Forty Niner, Nick, Shadow, halfelf Nov 21 at 2:30


Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.






closed as too broad by Barmar, Funk Forty Niner, Nick, Shadow, halfelf Nov 21 at 2:30


Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.










  • 3




    Hint: JOIN, WHERE.
    – Gordon Linoff
    Nov 20 at 22:30






  • 3




    what did you try so far?
    – mdem7
    Nov 20 at 22:32














  • 3




    Hint: JOIN, WHERE.
    – Gordon Linoff
    Nov 20 at 22:30






  • 3




    what did you try so far?
    – mdem7
    Nov 20 at 22:32








3




3




Hint: JOIN, WHERE.
– Gordon Linoff
Nov 20 at 22:30




Hint: JOIN, WHERE.
– Gordon Linoff
Nov 20 at 22:30




3




3




what did you try so far?
– mdem7
Nov 20 at 22:32




what did you try so far?
– mdem7
Nov 20 at 22:32












1 Answer
1






active

oldest

votes


















2














Your question is not clear but I will try my best to answer it.



To get the results you have posted:



select *
from Items_Table


Title says select all from a different table. I assume lists is the first table and items is the "different" table you are referring to.



Select Items.*
from Lists_Table Lists
left join Items_Table Items on Items.list_id = Lists.id


Now, lets assume you were looking for specific items, say where Id is 1 in the lists table. Then you would have the following:



Select Items.*
from Lists_Table Lists
left join Items_Table Items on Items.list_id = Lists.id
where Lists.id = 1


You can replace Lists.id in the where statement with any other column and set it equal to value you are looking for.



I hope this was helpful. Please try to be a bit more clear about what you are looking for!



Good Luck!









share|improve this answer



















  • 1




    It's a fairly safe bet that the JOIN condition should be items.list_id = lists.id
    – Nick
    Nov 20 at 22:43












  • Thanks @Nick. I made the appropriate changes.
    – MhQ-6
    Nov 20 at 22:56


















1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









2














Your question is not clear but I will try my best to answer it.



To get the results you have posted:



select *
from Items_Table


Title says select all from a different table. I assume lists is the first table and items is the "different" table you are referring to.



Select Items.*
from Lists_Table Lists
left join Items_Table Items on Items.list_id = Lists.id


Now, lets assume you were looking for specific items, say where Id is 1 in the lists table. Then you would have the following:



Select Items.*
from Lists_Table Lists
left join Items_Table Items on Items.list_id = Lists.id
where Lists.id = 1


You can replace Lists.id in the where statement with any other column and set it equal to value you are looking for.



I hope this was helpful. Please try to be a bit more clear about what you are looking for!



Good Luck!









share|improve this answer



















  • 1




    It's a fairly safe bet that the JOIN condition should be items.list_id = lists.id
    – Nick
    Nov 20 at 22:43












  • Thanks @Nick. I made the appropriate changes.
    – MhQ-6
    Nov 20 at 22:56
















2














Your question is not clear but I will try my best to answer it.



To get the results you have posted:



select *
from Items_Table


Title says select all from a different table. I assume lists is the first table and items is the "different" table you are referring to.



Select Items.*
from Lists_Table Lists
left join Items_Table Items on Items.list_id = Lists.id


Now, lets assume you were looking for specific items, say where Id is 1 in the lists table. Then you would have the following:



Select Items.*
from Lists_Table Lists
left join Items_Table Items on Items.list_id = Lists.id
where Lists.id = 1


You can replace Lists.id in the where statement with any other column and set it equal to value you are looking for.



I hope this was helpful. Please try to be a bit more clear about what you are looking for!



Good Luck!









share|improve this answer



















  • 1




    It's a fairly safe bet that the JOIN condition should be items.list_id = lists.id
    – Nick
    Nov 20 at 22:43












  • Thanks @Nick. I made the appropriate changes.
    – MhQ-6
    Nov 20 at 22:56














2












2








2






Your question is not clear but I will try my best to answer it.



To get the results you have posted:



select *
from Items_Table


Title says select all from a different table. I assume lists is the first table and items is the "different" table you are referring to.



Select Items.*
from Lists_Table Lists
left join Items_Table Items on Items.list_id = Lists.id


Now, lets assume you were looking for specific items, say where Id is 1 in the lists table. Then you would have the following:



Select Items.*
from Lists_Table Lists
left join Items_Table Items on Items.list_id = Lists.id
where Lists.id = 1


You can replace Lists.id in the where statement with any other column and set it equal to value you are looking for.



I hope this was helpful. Please try to be a bit more clear about what you are looking for!



Good Luck!









share|improve this answer














Your question is not clear but I will try my best to answer it.



To get the results you have posted:



select *
from Items_Table


Title says select all from a different table. I assume lists is the first table and items is the "different" table you are referring to.



Select Items.*
from Lists_Table Lists
left join Items_Table Items on Items.list_id = Lists.id


Now, lets assume you were looking for specific items, say where Id is 1 in the lists table. Then you would have the following:



Select Items.*
from Lists_Table Lists
left join Items_Table Items on Items.list_id = Lists.id
where Lists.id = 1


You can replace Lists.id in the where statement with any other column and set it equal to value you are looking for.



I hope this was helpful. Please try to be a bit more clear about what you are looking for!



Good Luck!










share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 20 at 22:56

























answered Nov 20 at 22:37









MhQ-6

255




255








  • 1




    It's a fairly safe bet that the JOIN condition should be items.list_id = lists.id
    – Nick
    Nov 20 at 22:43












  • Thanks @Nick. I made the appropriate changes.
    – MhQ-6
    Nov 20 at 22:56














  • 1




    It's a fairly safe bet that the JOIN condition should be items.list_id = lists.id
    – Nick
    Nov 20 at 22:43












  • Thanks @Nick. I made the appropriate changes.
    – MhQ-6
    Nov 20 at 22:56








1




1




It's a fairly safe bet that the JOIN condition should be items.list_id = lists.id
– Nick
Nov 20 at 22:43






It's a fairly safe bet that the JOIN condition should be items.list_id = lists.id
– Nick
Nov 20 at 22:43














Thanks @Nick. I made the appropriate changes.
– MhQ-6
Nov 20 at 22:56




Thanks @Nick. I made the appropriate changes.
– MhQ-6
Nov 20 at 22:56



Popular posts from this blog

To store a contact into the json file from server.js file using a class in NodeJS

Redirect URL with Chrome Remote Debugging Android Devices

Dieringhausen