Solved

Simple SQL problem

Posted on 2014-03-25
1
126 Views
Last Modified: 2014-03-25
Hi all!

I have a mysql table with contacts.

In this table I have a field called id_city and city_name.

I have another table called states where I have id_state, state_name and, related to it, all the id_city that are in that state.

I would like to prepare a query that shows me all the contacts living in all the city in a state using simply the state name...

How can I achieve this?
0
Comment
Question by:ltpitt
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 1

Accepted Solution

by:
ltpitt earned 0 total points
ID: 39952775
I think I did it!
I just needed a subquery:

SELECT allthefieldsyouneed
FROM youtable
where id_city = (select id_city from states where state_name = 'yourstatename')

Thanks anyway :)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

"In order to have an organized way for empathy mapping, we rely on a psychological model and trying to model it in a simple way, so we will split the board to three section for each persona and a scenario and try to see what those personas would Do,…
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This video teaches users how to migrate an existing Wordpress website to a new domain.

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question