Solved

query for two tables

Posted on 2004-08-06
7
200 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
[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
  • 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

Industry Leaders: 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

Suggested Solutions

Title # Comments Views Activity
css border raidius issue 7 97
SAMI File <SYNC Start = (number of millisecond)> Question 3 94
Problem to file 3 98
removing a class in javascript 4 92
Preface This article introduces an authentication and authorization system for a website.  It is understood by the author and the project contributors that there is no such thing as a "one size fits all" system.  That being said, there is a certa…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

738 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