Performing a nested select query in MYSQL with the wildcard character (*)

Within my incidents table, there are various fields including index, timestamp, refNum, priority, status, type, email, telephone, title, description, system, category, time, requiredBy, dateReason, oneOff, url, browserDevice, jsessionid, customersProducts, investigationsUndertaken, whatquestions, supportingInformation, and open.

I am a beginner in nesting queries and I am attempting to retrieve all records from the incidents table where either the title or status matches a keyword within a specified timestamp range. Individually, the queries work fine, but when nested together, I receive an error stating #1241 - Operand should contain 1 column(s). Can someone help me identify the mistake in my query?

SELECT
    *
FROM
    `incidents`
WHERE
     `timestamp` BETWEEN '2014-12-01 00:00:00' AND '2015-11-23 23:59:59'  
IN
(SELECT * FROM `incidents` WHERE `title` LIKE '%test%' OR `status` LIKE '%test%')

My desired outcome is to display all fields using *, filter them based on the timestamp range, and search for specific keywords within the title or status fields. In this case, I have used the keyword 'test' as an example.

Answer №1

It is essential to include an index column when writing a subquery to ensure the main query can retrieve specific data. Using SELECT * is not valid as there is no primary key specified. In this case, I have selected the column index (assuming it is an index).

SELECT
    *
FROM
    `incidents`
WHERE
     `timestamp` BETWEEN '2014-12-01 00:00:00' AND '2015-11-23 23:59:59'  
AND index IN
(SELECT index FROM `incidents` WHERE `title` LIKE '%test%' OR `status` LIKE '%test%')

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is there a way to divide a string that has two characters and store each of them in different variables?

I need to extract two characters from an array element by using a substring function. For instance, the value stored in the array element rank_tier is 52. I aim to store 5 into $firstnumber and 2 into $secondnumber. The error message I received is: A ...

Folder with a Unicode title containing Apache htdocs

I currently have my apache htdocs folder for Windows located at c:\anything1\怘怙怚怛\anything2. However, I am facing an issue where PHP scripts do not execute properly from this directory and instead display the following error message: ...

Failure to trigger AJAX Success or Error Events

I'm struggling to understand why this code isn't working or find any relevant resources. When I check the json object in Firebug, it either returns success: false or success: true from the post request, so I'm confused as to why the function ...

JSON object that is nested within another JSON object

After receiving a JSON output, I am now looking to extract the name of a page and not a rune. You can find the JSON output here. $decode_runes = json_decode($summoner_runes); I have attempted: $r = $decode_runes->{'name'}; as well as $r = ...

Failed to select mySql database using easyphp with error message "Database selection failed."

Recently delving into the world of PHP programming, I am seeking assistance with database selection code for MySQL within PHP. After creating a database named "admin" through phpMyAdmin, I noticed the name displayed as "[email protected]". To establis ...

When choosing from the drop-down menu, the selected box displays the ID instead of

Season's Greetings to everyone. Is everyone having a fantastic time? I am confident that my assumption is correct. Can someone assist me with this issue? I am puzzled as to why this code is returning the ID instead of the value when binding data from ...

Issue with flash installation

I'm currently working on a WordPress website at www.studium.cl. However, I've encountered an issue when trying to open it in Internet Explorer. Each time I try to access the site, a window pops up prompting me to install Adobe Flash Player. Even ...

What are your preferred HTMLPurifier configurations for sanitizing CSS styles?

I'm currently in the process of developing an application that allows users to input their own custom CSS for their profiles, similar to platforms like MySpace, Friendster, and Blogger. However, I'm struggling to find an effective method to prot ...

Explore the concealed features of Laravel like the hidden attributes such as password for enhanced security

As mentioned on http://laravel.com/docs/eloquent, the process of hiding attributes from array or JSON conversion can be achieved by utilizing a protected $hidden variable in the Model. class User extends Eloquent { protected $hidden = array('pass ...

Issues with assigning values to a variable in a PHP/MySQL prepared statement?

My PHP code contains a prepared statement with joins that is not assigning values to one of its variables: $dbRating = "x"; $dbFavDate = "x"; if($stmt = $dbcon->prepare(" SELECT i.*, u.username, r.rating, f.date_favorited FROM image i ...

Using PHP to remove a single Gmail contact from your list is a simple

I've encountered an issue while using a script to delete contacts from GMAIL. The script sometimes works, but it fails to delete specific contacts. For example, I'm attempting to remove "ADRIANA CALI" from the "modelos" group, but for some reason ...

Retrieve the names from one table by querying another table

I am working with a database that consists of 3 tables: Categories, Subcategories, and Articles. Within my Articles table, I have columns labeled CategoryID and SubcategoryID, both of which are foreign keys referencing the Categories and Subcategories tabl ...

Transform the character encoding from a non-standard format to UTF-8

Imagine a scenario where there is a page with <meta charset="EUC-KR">, let's call it address-search.foo.com, that allows users to search for an address and sends the data to a specified URL by submitting an HTML form using the POST met ...

PHP error: Trying to access an undeclared variable after using the require function

Currently, I'm facing a challenge while creating a PHP site. The issue is that I am unable to utilize included variables in the included files! index.php <?php require 'core/init.php'; ?> init.php <?php require 'config.php& ...

This route does not allow the use of the POST method. Only the GET and HEAD methods are supported. This limitation is specific to Laravel

I am encountering an issue while attempting to submit an image via Ajax, receiving the following error message: The POST method is not supported for this route. Supported methods: GET, HEAD. Here is the Javascript code: $("form[name='submitProfi ...

Iterating through an instance of stdClass named "object1"

object(stdClass)#1 (1) { ["trackingNo"]=> array(18) { [0]=> string(15) " 888005324912 " [1]=> string(16) " 1900530244582 " [2]=> string(15) " 778180519352 " [3]=> string(16) " 1000237325384 " Is there ...

Sending extensive information using PHP

Utilizing both stream_context_create and fopen, I am able to securely send data using the POST method in PHP. While $opts['http']['content'] functions beautifully, I now face the challenge of sending an exceptionally large file that ca ...

Show individual row information within a bootstrap modal upon clicking the edit button

As a beginner in programming, I am attempting to use bootstrap modal to showcase row data from a mysql table within the modal window. Following the advice found on stackoverflow regarding "Pull information from mysql table to bootstrap modal to edit" didn ...

The SSL certificate is functioning properly on my localhost through XAMPP, however, it is not working with localhost:9001

After creating an SSL certificate and key, I implemented it on my localhost (XAMPP). However, when attempting to access localhost:9001, the browser indicates that the certificate is invalid. https://i.stack.imgur.com/gyQgS.png https://i.stack.imgur.com/K ...

Creating an SQL select statement with a three-level expression is a complex task that requires careful planning and

How can I create a SQL select query with 3 levels of expressions and statements? Typically, my website operates on an SQLite database and the search results are displayed using the following SQL query: "SELECT DISTINCT * FROM amz WHERE Title LIKE \" ...