MS SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesMS SQL Development

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 December 31st, 2004, 09:08 PM
xsoftdev xsoftdev is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: Los Angeles, CA
Posts: 64 xsoftdev User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 51 m 7 sec
Reputation Power: 6
Exclamation Query not working

Hello All,

I am fairly new and am having a small problem that hopefully someone can shed some light on.

I have two tables with a one to many relationship, each user can have more than image.
[tbluser]
UserID
LoginName
BirthDate

[tblImage]
ImageID
UserID
ImageName
ProfileImage
Approved

My problem is that I am not able to select a distinct set of results of all users and the ImageName if that user has an image which is approved and ProfileImage is 'yes' or '1'. Can anyone help me with writing the correct SQL for this with some basic explanation. Thanks!!

Code:
SELECT tblUser.LoginName
, tblUser.BirthDate
, tblImage.ImageName
, tblImage.ProfileImage
, tblImage.Approved

FROM tblUser
 INNER 
JOIN tblImage ON tblUser.UserID = tblImage.UserID
WHERE (((tblImage.ProfileImage)=1) AND ((tblImage.Approved)=1));

I am using Access 2000 and using the Access Query builder.

Reply With Quote
  #2  
Old January 5th, 2005, 11:24 AM
paulh1983 paulh1983 is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Dec 2004
Posts: 1,255 paulh1983 User rank is Sergeant (500 - 2000 Reputation Level)paulh1983 User rank is Sergeant (500 - 2000 Reputation Level)paulh1983 User rank is Sergeant (500 - 2000 Reputation Level)paulh1983 User rank is Sergeant (500 - 2000 Reputation Level)paulh1983 User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 1 Week 1 Day 15 h 14 m
Reputation Power: 17
well i am not experienced either but two things come to my mind:

a) u have used tblImage.etc etc, but u havent declared it in the from clause ie from tbleuser, tblimage

b) it should be: where tableImage.profileImage = 1 AND tblImage.Approved = 1!

PS> just consulted my book and it appears i am wrong on my point a. so ignore it, i m leaving it in. as you may like to try it.1

also here is another query which should give you the same results:

Code:

select * from tblUser A, tblImage B
where A.userId = B.UserID AND B.Approved = " " AND B.ProfileImage IN ('Yes','1');


if that gives u duplicate replace select * with:

select distinct (*) from...

and finally if that doesnt work (it may not because of syntax problem)

try:

select distinct A.userID, A.LoginName, A.BirthDate from......


PS> i should mention that use of A and B is called alias, and it minimise the amount of writin u have to do! A and B could be anything u like/want!

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMS SQL Development > Query not working


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 3 hosted by Hostway
Stay green...Green IT