Question:
need help with SQL quries?
Rose
2008-03-15 09:18:51 UTC
following is question:

two tables (1) Address table and (2) city table,

How do I select address table and city table where city is 5 (las vegas).

Please help with query
Six answers:
2008-03-15 09:38:25 UTC
SELECT * FROM Address INNER JOIN City

ON Address.CityID = City.CityID

WHERE CityID = 5



I suggest you do some reading with the JOIN parameter (INNER JOIN, LEFT JOIN...), it'll answer a lot of your future questions.



G'luck.
TheMadProfessor
2008-03-15 10:06:09 UTC
While I can add little to the previous comments about joining the two tables, I can't help wondering why have two tables at all? There is such a thing as taking normalization to extremes and the added overhead of additional tables and more joins increasing query complexity makes this a dubious choice for a separate table.
ali_fakoor
2008-03-15 09:27:50 UTC
first crate a view "AddressCity" with the condition:



Address.CityCode = City. CityCode

(can be done by dragging the text of CityCode from one table to the corresponding on the other table in the view editor panel)



Then run this query



SELECT * from AddressCity

Where CityCode = 5
doug a
2008-03-15 10:12:35 UTC
SELECT *



FROM Address left outer join City on Address.CityID = City.CityID



WHERE CityID = 5
mouhammed_alhajj
2008-03-16 11:09:46 UTC
Use The Inner Join
mms4db
2008-03-15 09:41:24 UTC
I would add a caution here that, depending on field definitions, you may need quotes around your parameter value.



ie:

SELECT * from AddressCity

Where CityCode = '5'


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Continue reading on narkive:
Loading...