0

I am passing a list of journals in a query which contains special characters like &,-'() in the journal names. Here is what my query looks like:

select alt_id, citation.doi, citation.journal, citation.volume, 
citation.issue,  citation.pubdate, citation.title
from ALT_2018
where citation.journal in ('Mechanics & Astronomy', 'Women's Health', 'Current 
Directions in Psychological Science (Sage Publications Inc.)', 'Cement & 
Concrete Composites', 'Journal of Heart & Lung Transplantation', 'Infection control 
and hospital epidemiology (Online)', 'Journal of Research on Adolescence 
(Blackwell Publishing Limited)', 'Ophthalmic & Physiological Optics', 'Brain 
Structure & Function', 'New Solutions: A Journal of Environmental & 
Occupational Health Policy', 'European Physical Journal B -- Condensed 
Matter')

I tried using backslash to escape the special characters but it didn't work and I can't do it manually either because the list consists of 2000+ journals. Please help me out.

P.S. I am using SQL querying extension in Studio3T as the data is saved in MongoDB and is in json format

Bill Karwin
  • 538,548
  • 86
  • 673
  • 828
Tab Key
  • 171
  • 2
  • 15

1 Answers1

0

You can read about special characters in MySQL string literals here: https://dev.mysql.com/doc/refman/8.0/en/string-literals.html

If you need to use apostrophe characters, you can do it one of these ways:

'Women\'s Health'
'Women''s Health'
"Women's Health" -- only if sql_mode is not ANSI or ANSI_QUOTES

Those are the options. I don't know what you mean by "it didn't work" so I can't advise on how to fix it. I don't use Studio3T, so I can't guess what's preventing you from using one of these solutions.

There's nothing special about the & character in MySQL string literals.

Bill Karwin
  • 538,548
  • 86
  • 673
  • 828