473,385 Members | 1,356 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,385 software developers and data experts.

Require Help On A Query ---urgently

I am new to php and i am working on a project where i need to implement the following logic . Please help with the query ->

I have 3 tables ->
hotel ( HotelId,HotelName ) ([1,a],[2,b] , [3,c])
tags ( tagid,tagname,taggroupid) ([1,1star,1],[2,2star,1],[3,bar,2])
hoteltags ( HotelId,tagid)([1,1],[2,1],[3,1],[1,2],[3,2])

I have to apply an sql query that would give me the following results :

case 1 : Selection of 1star , 2star gives all hotelids containing both 1star and 2 star => (Intersect ) OUTPUT : 1

case 2 : Selection of 1star,bar gives all hotelids in 1star and bar -> 1,2,3


Can you pls help with the first case as i am not able to create an intersect query which will give me the above results .

For case 2 i was able to generate the foll query :
HotelId IN (SELECT hotelId FROM `hoteltags` WHERE tagId IN ( SELECT tagId FROM tags WHERE tagName IN (" . '1star' ,'2star' . ")))
Jan 14 '08 #1
1 1154
amitpatel66
2,367 Expert 2GB
I am new to php and i am working on a project where i need to implement the following logic . Please help with the query ->

I have 3 tables ->
hotel ( HotelId,HotelName ) ([1,a],[2,b] , [3,c])
tags ( tagid,tagname,taggroupid) ([1,1star,1],[2,2star,1],[3,bar,2])
hoteltags ( HotelId,tagid)([1,1],[2,1],[3,1],[1,2],[3,2])

I have to apply an sql query that would give me the following results :

case 1 : Selection of 1star , 2star gives all hotelids containing both 1star and 2 star => (Intersect ) OUTPUT : 1

case 2 : Selection of 1star,bar gives all hotelids in 1star and bar -> 1,2,3


Can you pls help with the first case as i am not able to create an intersect query which will give me the above results .

For case 2 i was able to generate the foll query :
HotelId IN (SELECT hotelId FROM `hoteltags` WHERE tagId IN ( SELECT tagId FROM tags WHERE tagName IN (" . '1star' ,'2star' . ")))
I would just modify your query slightly to get case 1:

Expand|Select|Wrap|Line Numbers
  1.  
  2. SELECT hotelname from hotel where hotelid IN(
  3. HotelId IN (SELECT hotelId FROM `hoteltags` WHERE tagId IN ( SELECT tagId FROM tags WHERE tagName IN (" . '1star' ,'2star' . "))))
  4.  
  5.  
Please make sure you use [code] tags when ever you post any source code
Jan 14 '08 #2

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

Similar topics

1
by: anil | last post by:
hello all i am anil kumar, pursuing master's degree in Computer applications . now i have got some opensource project. that is related to USB sniffing. tha t is snoopypro. Actalluy this is...
4
by: Nerry | last post by:
Hi everyone, i'm new to this forum and new to using ms access. I have a cleint table in a database, i want to be able to query that table to get details for one particular client. I've set...
0
by: chrislearner | last post by:
Hi All, I am new to this group and urgently require help from you guys!! I have to hard code the START date and the END date to 04/01/2006 and 06/30/2006 respectively. Here's the existing sql...
7
by: Jlo | last post by:
Hi, I have a c# winforms application. When I call the report file, it shows me all the records in the table. How can I make it to call only a particular range. i have the following code...
1
by: ramaswamynanda | last post by:
Hello all, I have a timesheet details table . I am trying to run the following query against it. SELECT ., . FROM timesheetdetails WHERE Format(,'dd/mm/yyyy') between '01/01/2007' and...
0
by: HR Head | last post by:
We urgently require following skill set for singapore client SAP CO-COPA Functional Lead: Person with a strong Costing background. Should have hands on SAP "COPA" experience Minimum two...
1
by: HR Head | last post by:
Hi, We urgently require SAP consultant with 5 year of SAP experience Qualification: - recognized Bachelors or Masters degree. Experience 1) 5 years of SAP work experience and a minimum...
3
by: altafur | last post by:
hi, i am using java with hibernate . i want to run a hibernate order by query thru java. i have written the query in hibernate.hbm.xml file. the query is as follows: query: SELECT distinct...
16
by: techystud | last post by:
Hi, I am doing a Left Join between two views wherein the column used in the ON condition has empty string rows in the first view. while running the query the application flashes, shows #ERROR...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.