Solved

MYSQL Query Help

Posted on 2014-12-26
4
203 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 32

Accepted Solution

by:
Stefan Hoffmann earned 500 total points
Comment Utility
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
Comment Utility
Sorry, it should read masterlist.UID=masterupload.uploadID.

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

Expert Comment

by:Stefan Hoffmann
Comment Utility
What error?
0
 

Author Comment

by:quimmy
Comment Utility
It worked after I tried your edited comment. Thanks!
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

All XML, All the Time; More Fun MySQL Tidbits – Dynamically Generate XML via Stored Procedure in MySQL Extensible Markup Language (XML) and database systems, a marriage we are seeing more and more of.  So the topics of parsing and manipulating XM…
Foreword This is an old article.  Instead of using the MySQL extension that was used in the original code examples, please choose one of the currently supported database extensions instead.  More information is available here: MySQLi / PDO (http://…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now