Solved

query for two tables

Posted on 2004-08-06
7
199 Views
Last Modified: 2010-04-06
i have two table, one for project name and the type of project like this

Project

ID     project_name
         
1      project one
2      project two
3      project three

Type

typeid          ID     type_project   minprice         maxprice
1        1        residential     2,717,000.00      4,197,000.00
2        1      commercial     408,000.00        983,000.00
3        1      industrial       399,600.00       1,000,000.00  
4        2      commercial     691,000.00         2,273,500.00
5        2      residential     263,000.00        2,267,000.00
6        3      commercial       194,700.00        341,500.00

my query is
Select * from project,type where type.minprice >= 500000 and type.maxprice <= 1000000 and project.ID = type.ID order by project.project_name asc"

it should display these:

2     1      commercial     408,000.00     983,000.00 = because 983,000.00 is less than 1000000

3     1      industrial    399,600.00          1,000,000.00  = because 1,000,000.00 is equal to 1000000

4     2      commercial     691,000.00         2,273,500.00 = because 691,000.00 is less than 1000000


what should be my query?

pls. help
       
0
Comment
Question by:amerliwayway
  • 2
  • 2
7 Comments
 

Author Comment

by:amerliwayway
ID: 11734299
the DB i am using is MS ACCESS
0
 
LVL 35

Expert Comment

by:YZlat
ID: 11734783
Select Type.typeid,Project.ID,Type.type_project,Type.minprice,Type.maxprice from project,type where type.minprice >= 500000 OR type.maxprice <= 1000000 and project.ID = type.ID order by project.project_name asc"
0
 
LVL 35

Expert Comment

by:YZlat
ID: 11734789
opps, replace OR with AND
0
 
LVL 7

Accepted Solution

by:
Tanglin05 earned 75 total points
ID: 11736631
SELECT Type.typeID, Project.ID, Type.type_project, Type.minprice, Type.maxprice

FROM Type INNER JOIN Project ON Type.ID = Project.ID

WHERE (Type.minprice >= 500000 AND Type.maxprice <= 1000000)

ORDER BY Project.project_name;
0
 
LVL 7

Expert Comment

by:Tanglin05
ID: 11736659
It is always better for security and performance not to use the "*" wildcard in database select statements. Otherwise, the INNER JOIN is a more graceful way of connecting your two tables- where all records with matching values will be returned.

To learn more about forming SQL statements, this web site is VERY helpful and easy to use:

http://www.w3schools.com/sql/default.asp
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to i line up css containers from left to right 35 23
PHP email variable syntax 3 53
File names with & character 6 84
replace quotes with UTF-8 character 38 108
This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

820 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