query

How to do this query in mysql?

SELECT item_name from items WHERE item_id = $var; I tried: $var = 001 || 002 || 003 || 004; $var = 001 OR 002 OR 003 OR 004; $var = 001 or 002 or 003 or 004; But all do not work. Thanks, i try that, but the output only 1 result => 1. What I want is to output all, i.e. 1, 2 , 3 and 4.. Means, I want to select multiple records(rows...

How to select multiple records (row) from a column in mysql?

I want to display four (4) items'name from these id: Can I do like this? SELECT item_name from items WHERE item_id IN ('001', '012', '103', '500') or SELECT item_name from items WHERE item_id = '001' or item_id = '012' or item_id = '103' or item_id = '500' IN RESPONSE TO ALL ANSWERS Well, most of the answers said it works, but it do...

Optimizing Mysql Table Indexing for Substring Queries

Hi All, I have a MySQL indexing question for you guys. I've got a very large table (~100Million Records) in MySQL that contains information about files. Most of the Queries I do on it involve substring operations on the file path column. Here's the table ddl: CREATE TABLE `filesystem_data`.`$tablename` ( `file_id` INT( 14 ) NOT...

MS SQL2005 Query/Stored Proc Results To Text using SqlCommand or such

I have a simple question. I need to return results as simple text, either as a string or similar. ie I want the same behaviour such as Results to Text (Cntrl + T) when you run a Query from SQL Server Management Studio. How can this be done programatically against calling a Stored Proc from C#? ie similar to ExecuteReader(); or ...

XPath 1 query

Hi, I posted a similar question and I got a very useful reply. Now the question is a little different, so I post it. I specify it is an XPath 1 related question. This is the content of my XML file: <?xml version="1.0" encoding="ISO-8859-1"?> <mainNode> <subNode> <h hm="08:45"> <store id="1563">Open</store> </h> ...

How to optimize query looking for rows where conditional join rows do not exist?

I've got a table of keywords that I regularly refresh against a remote search API, and I have another table that gets a row each each time I refresh one of the keywords. I use this table to block multiple processes from stepping on each other and refreshing the same keyword, as well as stat collection. So when I spin up my program, it qu...

Using a SELECT Statement in the WHERE IN Clause i.e. WHERE blah in (SELECT b...)

Hi, I am trying to do some complex pivot query... and I need to do a select in the IN Clause... Example of the Pivot Looking at the Example in the above link, you can see they use the employee ids explicitly in their pivot. I would like to be able to do select instead of specifying the employee ids. The only way I can think of doing...

"INSERT IGNORE" vs "INSERT ... ON DUPLICATE KEY UPDATE"

While executing an INSERT statement with many rows, I want to skip duplicate entries that would otherwise cause failure. After some research, my options appear to be the use of either: "ON DUPLICATE KEY UPDATE" which implies an unnecessary update at some cost, or "INSERT IGNORE" which implies an invitation for other kinds of failure...

mysql keyword search

I have a table with names of movies, and I want to be able to search for a movie in that table. But I want to be able to search for part of the title, and still return a result. For example, if there is a record with the name "The quantum of solace", then I want to be able to do a search for "quantum solace", or even "007: quantum solace...

Quickest way to prevent SQL returning data older than Given

Hey there I have a pretty complex database with loads of different tables for different things, every thing of which has a timestamp (Y-M-D h:m:s format) Is there a way I can limit my SQL query to just results from a certain timespan, for example a week ago? If needbe I have a function to convert these timestamps into unix as sqlToUn...

Best way of acquiring information from several database tables

I have a medical database that keeps different types of data on patients: examinations, lab results, x-rays... each type of record exists in a separate table. I need to present this data on one table to show the patient's history with a particular clinic. My question: what is the best way to do it? Should I do a SELECT from each table w...

Table Group By - Tsql -

The first picture is my query. I need to obtain results in second picture. What to do? Which query do have to use? Select OrarioA, OrarioB, Max(IDOrario), (????)IDDettaglioOrarioA, (???)IDDettaglioOrarioB FROM TABLE GROUP BY OrarioA, OrarioB, ?????????????? I need respective IDDettaglioOrarioA, IDDettaglioOrarioB. How to complet...

Need a Complex SQL Query

Hey, I need to make a rather complex query, and I need help bad. Below is an example I made. Basically, I need a query that will return one row for each case_id where the type is support, status start, and date meaning the very first one created (so that in the example below, only the 2/1/2009 John's case gets returned, not the 3/1/200...

SQL Looping

I'm building this report in a system for a Billboard company. They have a table that stores all their billboards, and among other data, billboards have a Start Date and a Finish Date (both can be null). If for some reason a billboard has to stop beeing used, they set a finish date and it will become unnavaiable to be used after that date...

Query Performance - Inner Join

I have this query and I want to improve performance: SELECT OrarioA, OrarioB, IDOrario, IDDettaglioOrarioA, IDDettaglioOrarioB FROM ( SELECT Tb_01.Orario AS OrarioA, Tb_02.Orario AS OrarioB, Tb_01.IDDettaglioOrariLinee AS IDDettaglioOrarioA, Tb_02.IDDettaglioOrariLinee AS IDDet...

SQL query filtering

Hey, Using SQL Server 2005, I have a table where certain events are being logged, and I need to create a query that returns only very specific results. There's an example below: Log: Log_ID | FB_ID | Date | Log_Name | Log_Type 7 | 4 | 2007/11/8 | Nina | Critical 6 | 4 | 2007/11/6 | John | Critical ...

How many MySQL queries should I limit myself to on a page? PHP / MySQL

Okay, so im sure plenty of you have built crazy database intensive pages... I am building a page that I'd like to pull all sorts of different / unrelated databse information from....here are some sample different queries for this one page: -article content and info -IF the author is a registered user, their info -UPDATE the article's...

retrieving variable from intermed table

I need to retrieve institution name by going through an intermediate table. My view gets all the values except this one or at least it is not displaying in the template. Can someone please help with either revising my view or template statement? http://dpaste.com/122204/ Thank you, May ...

How to put IF statement in MySQL query

Hey all! I have a query that is simply selecting from 3 tables. select from the comments table for all comments on an article select from UserID table to find what kind of user it is IF the user is one type, search one table...ELSE search another table for the final info. How would I go about this? I'm a little new at MySQL stuff, s...

What's wrong with this query? EXPLAIN looks fine to me...

I'm going through an application and trying to optimize some queries and I'm really struggling with a few of them. Here's an example: SELECT `Item` . * , `Source` . * , `Keyword` . * , `Author` . * FROM `items` AS `Item` JOIN `sources` AS `Source` ON ( `Item`.`source_id` = `Source`.`id` ) JOIN `authors` AS `Author` ON ( `Item`.`author...