Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

The Database Forum


You are currently viewing our The Database Forum as a guest. Please register to participate.
Login



Reply
Need help modifying query
Old 11-06-2008, 12:00 PM Need help modifying query
drew22299's Avatar
Skilled Talker

Posts: 93
Trades: 0
Hi,

I have 4 tables, Branch, Client, user and userPreferredLocation. Each client has multiple branches and a user has preferred branches they like to visit.

Currently, the query returns branches that require users and doesn't include branches that users like to visit. Is there any way I can modify the query to return all of the branches a user has selected?

Here's my attempt but it doesn't work, can anyone see why?

SELECT Branch.*, Client.Name AS ClientName, Client.Name +' '+ Branch.Name AS Fullname,
PreferredLocation.Location AS Location, User.UserUID As User
From Client INNERJOIN Branch ON Client.ClientUID=Branch.ClientUID
AND Location INNERJOINON Location.UserUID=User.DineerUID
Where Branch.DinerRequired = 1
Orderby Client.Name, Branch.Name

Last edited by drew22299; 11-06-2008 at 12:26 PM..
drew22299 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 11-06-2008, 01:00 PM Re: Need help modifying query
Brian07002's Avatar
Defies a Status

Posts: 2,141
Name: ...
Location: ...
Trades: 0
Your best bet in simple terms is to use PhpMyAdmin as it has all the search tools for SQL queries that you will ever need...You will have to get used to them at first. Good Luck

Hth
__________________
Made2Own

Please login or register to view this content. Registration is FREE
Brian07002 is online now
Reply With Quote
View Public Profile
 
Old 11-06-2008, 02:11 PM Re: Need help modifying query
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,519
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Should we guess at the table structure and how the PKs and FKs are set up?
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 11-06-2008, 02:15 PM Re: Need help modifying query
Learning Newbie's Avatar
Defies a Status

Latest Blog Post:
Astounding Republican Paranoia
Posts: 5,662
Name: John Alexander
Trades: 0
Quote:
Originally Posted by drew22299 View Post
Currently, the query returns branches that require users and doesn't include branches that users like to visit. Is there any way I can modify the query to return all of the branches a user has selected?
Change your joins. Requires means an inner join - if you'd like correlated data, but for it to be optional, use an outer (left or right) join instead. As Chris pointed out, you're the only one here who knows your schema, so you'll have to work out how to query the data as it's modeled.
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
Learning Newbie is offline
Reply With Quote
View Public Profile
 
Old 12-18-2008, 11:19 AM Re: Need help modifying query
drew22299's Avatar
Skilled Talker

Posts: 93
Trades: 0
Looks like I forgot to check for replies to this question! Thanks for your replies even though I posted this well over a month ago lol
drew22299 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Need help modifying query
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.22868 seconds with 12 queries