Database Management
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesDatabase Management

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old September 14th, 2003, 02:10 AM
chondhe chondhe is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: Bombay
Posts: 9 chondhe User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Contain Command in Access SQL

I'm looking for the equivalent syntax of "Contain" in SQL for querying in Access SQL.. The code is given below for which i want an alternative in Access SQL

select *
from student
where
(select Accno from Borrow
where Borrow.Sno = Student.Sno
contains
(select Accno from Book
where Title like "DBMS"))

The tables are:
Student(Sno, Name, College)
Borrow(Sno, Accno, DOI)
Book(Accno, Title, Cost)

Reply With Quote
  #2  
Old September 14th, 2003, 02:38 PM
r937's Avatar
r937 r937 is offline
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 17,913 r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level) 
Time spent in forums: 1 Month 4 Weeks 12 h 24 m 34 sec
Reputation Power: 1018
try this:
Code:
select Student.Sno, Student.Name, Student.College 
  from Student 
inner
  join Borrow 
    on Student.SNo = Borrow.Sno
inner
  join Book 
    on Borrow.Accno = Book.Accno 
 where Book.Title = 'DBMS'
i changed your LIKE to an equality test because you used no wildcards

rudy
http://r937.com/

Reply With Quote
  #3  
Old September 15th, 2003, 02:22 AM
chondhe chondhe is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: Bombay
Posts: 9 chondhe User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Contain Command in Access SQL

Hi... Rudy
Thanx for replying... but the result of the query that you submitted gives me the list of people who borrowed any book on DBMS whereas I was looking for a query that would display people who had borrowed all the books on DBMS... not any

Thanx,
Chondhe

Reply With Quote
  #4  
Old September 15th, 2003, 10:54 PM
r937's Avatar
r937 r937 is offline
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 17,913 r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level) 
Time spent in forums: 1 Month 4 Weeks 12 h 24 m 34 sec
Reputation Power: 1018
ah, okay, i understand now

never saw "contains" before, but your explanation makes it clear

sounds like a set operation, and who knows, it might be part of sql2003 or whatever the latest standard is, but i doubt access supports it

anyhow, here's how i'd approach the problem --
Code:
select Student.Sno, Student.Name, Student.College 
     , count(Book.Title)
  from Student 
inner
  join Borrow 
    on Student.SNo = Borrow.Sno
inner
  join Book 
    on Borrow.Accno = Book.Accno 
 where Book.Title like '%DBMS%'
group
    by Student.Sno, Student.Name, Student.College
having count(Book.Title)
     = ( select count(*)
           from Book 
          where Book.Title like '%DBMS%' )

i changed the WHERE back to LIKE since you are looking for several titles

let me know if that works

rudy

Reply With Quote
  #5  
Old September 22nd, 2003, 02:03 AM
chondhe chondhe is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: Bombay
Posts: 9 chondhe User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Hi Rudy..

Thanx a lot mate for the query. It worked as I wanted it. Correct results. I had actually read that the contain command was part of the ANSI SQL standards of 92 and 99.. so i thought that it'd work here with access.

Thanx once more.

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesDatabase Management > Contain Command in Access SQL


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT