Final answer:
To add a single quote to an SQL query, use another single quote as an escape character. For instance, O'Reilly becomes O''Reilly in an SQL string. When quoting a quote within another quote, double the single quotes for the internal quote and use single quotes to enclose the entire string.
Step-by-step explanation:
To add a single quote in an SQL query string, you should use an escape character, which is usually another single quote. This technique is commonly referred to as escaping the quote. For example, to include the word O'Reilly in an SQL query, you would write O''Reilly, doubling the single quote within the string.
If you are including a quoted piece of text within another quote, SQL requires single quotes for string literals. Thus, when you're inserting a text value into a database column, which in turn contains a quotation, use a single quote to start and end the entire string and double up the single quote where you want to include the actual quote in the string. For example, a query to insert a text containing a quote would look like this: INSERT INTO table_name (column_name) VALUES ('Here''s the quoted "quote within a quote" text.');