?
Solved

Simple SQL problem

Posted on 2014-03-25
1
Medium Priority
?
135 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
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
Ready to get certified? Check out some courses that help you prepare for third-party exams.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

839 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