Solved

MYSQL Query Help

Posted on 2014-12-26
4
209 Views
Last Modified: 2014-12-26
I am attempting to write an mysql query where I pull information from 2 tables based on certain parameters. I have the following query working as I need it to:

"SELECT * FROM masterlist, masterupload WHERE UID=uploadID AND masterlist.client='ClientName' ORDER BY entry ASC"

What I need to add to this query is a condition that will return exactly what is stated above, OR all entries from masterlist where client="ClientName", without the condition that UID=uploadID as there will be cases where an entry exists in masterlist without a matching entry in masterupload. Make sense? I don't know if I need to do some type of JOIN to accomplish this, but would appreciate the help. Thanks!
0
Comment
Question by:quimmy
  • 2
  • 2
4 Comments
 
LVL 33

Accepted Solution

by:
ste5an earned 500 total points
ID: 40518470
First of all: Please use the JOIN syntax and table alias names to increase readability. The problem is where is UID coming from?

I guess it's a LEFT JOIN you need:

SELECT 	L.*,
	U.*
FROM 	masterlist L
	LEFT JOIN masterupload U ON L.UID = U.uploadID
WHERE 	L.client = 'ClientName' 
ORDER BY L.entry ASC;

Open in new window

0
 

Author Comment

by:quimmy
ID: 40518473
Sorry, it should read masterlist.UID=masterupload.uploadID.

I tried your suggested query and get an error.
0
 
LVL 33

Expert Comment

by:ste5an
ID: 40518476
What error?
0
 

Author Comment

by:quimmy
ID: 40518539
It worked after I tried your edited comment. Thanks!
0

Featured Post

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I use MySQL for many of my development projects in a Windows environment. To manage my databases (and perform queries) for years I used a tool called MySQL administrator.  This tool has since been replaced by MySQL Workbench. So I decided to m…
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question