Solved

MYSQL Query Help

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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

This guide whil teach how to setup live replication (database mirroring) on 2 servers for backup or other purposes. In our example situation we have this network schema (see atachment). We need to replicate EVERY executed SQL query on server 1 to…
As a database administrator, you may need to audit your table(s) to determine whether the data types are optimal for your real-world data needs.  This Article is intended to be a resource for such a task. Preface The other day, I was involved …
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

789 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