Solved

MYSQL Query Help

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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

More Fun with XML and MySQL – Parsing Delimited String with a Single SQL Statement Are you ready for another of my SQL tidbits?  Hopefully so, as in this adventure, I will be covering a topic that comes up a lot which is parsing a comma (or other…
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…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

813 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