Solved

Simple SQL problem

Posted on 2014-03-25
1
124 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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

"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,…
Any business that wants to seriously grow needs to keep the needs and desires of an international audience of their websites in mind. Making a website friendly to international users isn’t prohibitively expensive and can provide an incredible return…
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…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

707 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now