473,387 Members | 1,512 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How to get values from 2 tables

117 100+
hi,
i am new in SQL, i need this.

i have two tables (1) - Hotel (2) - Rates in 1st table i have fields autoid, name, rating, description and in
2nd table i have periodfrom, periodto, singleroomrate, doubleroomrate, RefHotelid
here period from and periodto are the datetime fields having the validatiy of rates tariff, suppose hotel A says
from this date to this date our rate sheet will be this but will be diferent from next month to additional 2 months
and RefHotelId is the basically the AutoId of the 1st Table, it can be repeated because single hotle can have many rate tariff
within a month or within a year.
so i wnat to select the name and description from first hotel where hotel rating is 2 and rest of the info means rates from 2nd table
based on selected autoid from 1st table for desired rating hotel how cna i get this.

like what i made query but it shows strange results.

select A.HotelName,B.SglPayableRate [Single Room Rate],B.DblPayableRate [Double Room Rate],B.TSUPayableRate [TSU Room Rate],B.QuadPayableRate [Quarter room Rate] from tblHotel A INNER JOIN tblHotelTariff B ON B.RefHotelID = (Select AutoID from tblHotel where StarRating = 2) AND PeriodFrom >= '5/25/2007' and PeriodTo <='6/2/2007'
Feb 27 '07 #1
3 2008
Plz try this query when u have 1)Hotel 2)Rates tables

Code:
Select h.Name,r.Singleroomrate,r.doubleroomrate
from Hotel h inner join rates r on h.autoid=r.refhotelid
where r.periodfrom>='2007-01-01' and r.periodto<='2007-01-31'
and h.rating=2
Feb 27 '07 #2
sani723
117 100+
Plz try this query when u have 1)Hotel 2)Rates tables

Code:
Select h.Name,r.Singleroomrate,r.doubleroomrate
from Hotel h inner join rates r on h.autoid=r.refhotelid
where r.periodfrom>='2007-01-01' and r.periodto<='2007-01-31'
and h.rating=2

dear this query is not returing anything although there are values against the date what i am entering
Feb 27 '07 #3
dear this query is not returing anything although there are values against the date what i am entering
I am surprised why it is not returning any value.Check the date format which u supply for filteration should be yyyy-mm-dd.

I try on following table structure
[Hotel table]

AutoID int 4 1
Name varchar 50 1
Rating int 4 1

[Hotel values ]

1 AWARI 1
2 PC 1
3 AKW 2

*************
[Rates table]

RefHotelId int 4 1
periodfrom datetime 8 1
Periodto datetime 8 1
Singleroomrate float 8 1
doubleroomrate float 8 1
[Rates table values]

1 01/01/2007 01/31/2007 500 800
2 01/01/2007 01/31/2007 400 600
3 01/01/2007 01/31/2007 200 350
1 01/02/2007 02/28/2007 550 1000
2 01/02/2007 02/28/2007 430 500
3 01/02/2007 02/28/2007 275 450
**************************
Query result which i send to u

AKW 200.0 350.0
**************************************
Practice this own ur side. I think you will got it now.

Regards,
Feb 27 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Programmer | last post by:
Hi All Here is my problem I'm using a SQLDataAdapter and DataSet I use the method FillSchema(myDataset, SchemaType.Source) The problem is that when i Check the default Values of the Dataset...
2
by: MLH | last post by:
Gentlemen: I have declared an array Dim MyTables(14) AS Long Now I want to assign values for MyTables(0) - MyTables(14) equal to the number of records in each table. Catch, I want the code...
13
by: scorpion53061 | last post by:
Very urgent and I am very close but need a little help to get me over the edge........ I need to write these columns to a html file with each row containing these columns (seperated by breaks)....
4
by: Jim in Arizona | last post by:
This doesn't make any sense to me. I'm hoping some SQL guru out there knows the answer. I'm making a help desk type database system. There's only two tables, one called TTickets and the other...
4
by: Rob | last post by:
Hi, I've been going at this for a few days and can't see the problem. Does anyone see a problem with this code? I have a call to a function that returns a dataset and when I assign values to...
2
by: Tony Dong | last post by:
HI there I make a data binding for list box, and it is multi selects, everything working fine, but How can I get the multi select values in windows form? I try many ways for...
3
by: dbuchanan | last post by:
Hello, (Windows forms - SQL Server) I fill my datagrid with a stored procedure that includes relationships to lookup tables so that users can see the values of the combobox selections rather...
4
by: satish | last post by:
Values of two columns in two different tables--presentation using select Hi Everyone, i have two tables in the database . One is called address table and one is adressPhone Table. Below...
0
by: cmrhema | last post by:
Hi, I have two controls one html select control and one asp.net dropdownlist control. In html select control i have three maps loaded. It is loaded in the following manner. <SELECT...
7
by: sparks | last post by:
I am working on a database that has a lot of calculated values on the forms. These were never put into the tables. But were tied to unbound fields on the forms. Now 8000 records later they want...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.