MySQL Complex Search help

Hello everyone,

I need some help regarding a complex query I am trying to run.

I have 2 tables.  One called Document_List, one called File_Detail.

They both have docID, which is the relationship between the 2 tables.

I want to search this:

Give all rows from File_Detail
Where Document_List.Flag = 6
And File_detail.NotesID = 0

This is my attempt, its almost there, but the notesID = 0 is not working:

select p2.file_detail.* from p2.file_detail 
left join p2.document_list on p2.file_detail.docnumber = p2.document_list.docnumber and p2.file_detail.notesid = 0
where p2.document_list.import_flag = 6;

Open in new window


Can anybody point out where I'm going wrong here please?

Thanks very much!

Darren
dbridleAsked:
Who is Participating?
 
SharathConnect With a Mentor Data EngineerCommented:
>> This is my attempt, its almost there, but the notesID = 0 is not working:
What do you mean by not working. Are you getting empty result set? run this and see the result.
select p2.file_detail.* from p2.file_detail 
left join p2.document_list on p2.file_detail.docnumber = p2.document_list.docnumber and p2.file_detail.notesid = 0
and p2.document_list.import_flag = 6;

Open in new window

0
 
Aaron TomoskySD-WAN SimplifiedCommented:
select p2.file_detail.* from p2.file_detail
left join p2.document_list on p2.file_detail.docnumber = p2.document_list.docnumber
Where
p2.file_detail.notesid = 0
And p2.document_list.import_flag = 6;
0
 
dbridleAuthor Commented:
Thanks for the response guys.

Aaron, your suggestion ended up with the same result set.

Sharath, what I mean by not working, is that I get notesID's of 1, 2, 3 or whatever the value is, when I only want notesid = 0.  I also tried your solution, and the import_flag = 6 is not taking effect, so the notesid is working, but its returning the wrong results from document_list.

Thanks for your help so far!
0
Improve Your Query Performance Tuning

In this FREE six-day email course, you'll learn from Janis Griffin, Database Performance Evangelist. She'll teach 12 steps that you can use to optimize your queries as much as possible and see measurable results in your work. Get started today!

 
SharathData EngineerCommented:
Can you run this and see the result?
SELECT p2.file_detail.* 
  FROM p2.file_detail 
       LEFT JOIN p2.document_list 
         ON p2.file_detail.docnumber = p2.document_list.docnumber 
            AND p2.document_list.import_flag = 6 
 WHERE p2.file_detail.notesid = 0;

Open in new window

0
 
dbridleAuthor Commented:
Hi Sharath,

Same result, the import_flag = 6 is not being processed.
0
 
SharathData EngineerCommented:
Is it possible to post the result of my last query and the expected result?
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
change LEFT JOIN to INNER JOIN
0
 
dbridleAuthor Commented:
Tried all of the above variants with INNER JOIN, with no success.

Sharath, I can't post the result set as it contains sensitive data.  I'm trying to think of the best way to replicate the issue.  Perhaps if I sent a create statement of the 2 tables? I'm not sure.
0
 
SharathData EngineerCommented:
I asked sample output because I don't understand by "Same result, the import_flag = 6 is not being processed."
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
hmmmm...

select f.* , f.*
 from p2.file_detail f
left join p2.document_list d
  on f.docnumber = d.docnumber 
 and d.import_flag = 6
where f.notesid = 0;

Open in new window

0
 
dbridleAuthor Commented:
Angelll,

The following was in teh result set for notesID - "AFFF8329531912DA802575F40048BDB0".

All results had an import flag of 6.
0
 
dbridleAuthor Commented:
Sharath--

"I asked sample output because I don't understand by "Same result, the import_flag = 6 is not being processed.""

I am essentially querying 2 result sets.  The outer result set, which is document_list where import_flag = 6 and in the enner result set, which is file_detail where notesid = 0.

On all of the above idea's, either one or the other where clause works, but never both of them.

So when I say import_flag = 6 is not being processed, or "did not work", what I mean is, that the where clause was ignored.

Hope that helps!
0
 
Guy Hengel [angelIII / a3]Connect With a Mentor Billing EngineerCommented:
mysql does not ignore clauses.

please post "sample" data, meaning just the relevant part of the output. sensitive data cleared/anonymized.
0
 
dbridleAuthor Commented:
I de-sensitized the field names, because it was becoming a hastle.

Here is the query:

select p2.neocol_extraction_file_detail.* 
    from p2.neocol_extraction_file_detail 
        inner join p2.neocol_extract_document_list 
            on p2.neocol_extraction_file_detail.f_docnumber = p2.neocol_extract_document_list.f_docnumber
where p2.neocol_extraction_file_detail.notesid = 0
    and p2.neocol_extract_document_list.import_flag = 6;

Open in new window


Here is a sample results set, with the sensitive data removed and replaced by ***

application/pdf,***, AFFF8329531912DA802575F40048BDB0, 2785437, , 1212671
application/pdf, ***,AFFF8329531912DA802575F40048BDB0, 2785445, , 1212672
application/pdf, ***,D048A4D4CAED8C60802575F6003669A7, 2786092, , 1212680
application/pdf, ***,FF56A4995ED72066802575F6003A4375, 2786240, , 1212684
application/pdf, ***,FF56A4995ED72066802575F6003A4375, 2786257, , 1212685
application/pdf, ***,0, 2786434, , 1212691
application/pdf, ***,BD521712BD104949802575F900449A7A, 2786455, , 1212692

Open in new window


Columns:
Mime Type, Path (***), NotesID, DocID,2ndPath (Usually Blank) , Unique File ID

As you can see from the above query, there is only 1 result in that set that should be there (the notesid = 0.

Here is the table containing the import_flag:

2785437, 46, 1, 1, 6, 14451, 0, 
2785445, 46, 1, 1, 6, 14451, 0, 
2786092, 12, 1, 1, 6, 14451, 0, 
2786240, 5, 1, 1, 6, 14451, 0, 
2786257, 5, 1, 1, 6, 14451, 0, 
2786434, 6, 1, 1, 6, 14451, 0, 
2786455, 12, 1, 1, 6, 14451, 0, 

Open in new window


Columns - Docid, DocClasNum, export_flag, conversion_flag, import_flag (6), entryid, encrpyted_flag.

This is a subset of around 4 million rows, not sure if that has any baring!

Hope that helps.

Darren
0
 
dbridleAuthor Commented:
Sometimes, you can work too hard and start to miss stupid things, like not surrounding a string with '.  Changed it to notesid = '0' and works fine.

Really sorry to have wasted your time folks, will split the points between you.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.