database-queries

In mysql How can I multiply two tables?

Basically what I want is cross product of two tables. t1 is : +------------+ | student | +------------+ | 1234567890 | | 1234567890 | | 1234567890 | | 000000001 | +------------+ t2 is: +--------+ | number | +--------+ | 1 | | 3 | +--------+ How can I get a tab...

Approach to sending alerts with CakePHP

This is a rather obscure question so please bare with me. It's more about approach than syntax. I have a MySQL table filled with 'notifications' (id,user_id,date,etc). I have to send an alert (via email, facebook, twitter, whatever... not the issue) when each of those entries pings as 'true'. Here's the thing, how should I go about ping...

Any dynamic database frontend tool from which you can update directly?

Hi Gurus, This is with reference to this question where I got one tabular report format. I need to update the user entered values correctly back to the same table rows. I am in the process of doing this by using general form post data methods by using some logics which I think will not be easy to maintain. So, just out of curiosity, Is...

Selecting the items associated with a tag along with the tags associated with these items

2 tables: items(item_id, ...) tags(tag_id, item_id) How do I select the items (from the "items" table) that have a particular tag associated with them (in the "tags" table) along with all the tags associated with these items? ...

Need help with MySQL query for Wordpress

My problem is not with Wordpress's WPDB class, but with the MySQL syntax. I'm trying make the following sequence work: Get an array of all Posts IDs Filter out posts from a specific Category Filter out duplicates, revisions, drafts etc. Only show Published content. Help? Thank you. ...

Selecting with 2 JOINs to get a count and a concatenated string

3 tables: items(item_id, ...) tags(item_id, tag_name) downloads(item_id, ...) How do I select a single item together with the number of occurrences of this item in the downloads table and all tag_name values associated with that item? Tried: SELECT ..., COUNT(downloads.item_id) AS download_count, GROUP_CONCAT(tags.tag_nam...

Find "old" rows

Consider a table like this: | txn_id | account_id I'd like to do a single query that will get me all txn_ids for all transactions where the transaction is not the most recent (highest txn_id) for the account_id . The database is MySQL 5.1, so that might imply some limitations around sub-selects. ...

mysql - search between dates where all dates appear

I'm working with some imported data that stores details about whether a "room" is available on a specific day or not. Each room has an individual entry for the date that it is available. | id | date | price | -------------------------------- | 1 | 2010-08-04 | 45.00 | A user can search across a date range and the sea...

Database Records Sorting

is there any query that would go n sort recods in the data-base via any column. I don't want the a "Ordered Result". i want the stored records rearranged and sorted. ...

MYSQL Searching by Zip Code

I am having a tough time searching by zip, which wasn't a problem before and will most likely be an easy problem for a MySQL / PHP programmer. I have a database full of house listings that I need to search by various fields. I have no problem searching by city, until I search by zip code (which like I said used to work). Anyways here i...

Getting hierarchy data from a self-referencing table

Let's say you have the following table: items(item_id, item_parent) ... and it is a self-referencing table as item_parent refers to item_id. What SQL query would you use to SELECT all items in the table along with their depth where the depth of an item is the sum of all parents and grand parents of that item. If the following is the co...

SQL - NOT IN explained

I am working in a project which needs top performance in SQL results, and was looking to optimize a query, but after some trial and error I am having some trouble with IN. -- THIS RETURNS NO RESULTS AT ALL. SELECT sysdba.HISTORY.TICKETID FROM sysdba.HISTORY where TICKETID = 't6UJ9A002MJC' ...

Selecting the latest per group of items

i have 2 tables products and cost PRODUCT ProdCode - PK ProdName COST Effectivedate - PK RetailCOst Prodcode i tried this query: SELECT a.ProdCOde AS id, MAX(EffectiveDate) AS edate, RetailCOst AS retail FROM cost a INNER JOIN product b USING (ProdCode) WHERE EffectiveDate <= '2009-10-01' GROUP BY a.ProdCode; uhm yah its show...

Getting parental status from a self-referencing table

Let's say you have the following table: items(item_id, item_parent) ... and it is a self-referencing table as item_parent refers to item_id. What MySQL supported SQL query would you use to SELECT each item in the table along with a boolean value that indicates whether that item is a parent / has other items referencing to it? If you ha...

Split Address column into separate columns in SQL view

I have an Address column in a table that I need to split into multiple columns in a view in SQL Server 2005. I need to split the column on the line feed character, chr(10), and there could be from 1 to 4 lines (0 to 3 line feeds) in the column. Below are a couple of examples of what I need to do. What is the simplest way to make this h...

Check if Database Exists Before Creating

This seems pretty trivial, but it is now frustrating me. I am using C# with SQL Server 2005 Express. I am using the following code. I want to check if a database exists before creating it. However, the integer returned is -1 and this is how MSDN defines what ExecuteNonQuery() will return as well. Right now, the database does exist but ...

What is the best algorithm for finding related post?

Basically this is a database and query question. How do you implement related post in your site, suppose you have this table: +------+ +------+ + Post + + Tags + -------- N : M -------- where post have the body and link m:n to tag. This is a very common scenario of implement tag and post. so, How do you implement rela...

SQLite table design question

I'm working on a program that deals with invoices for services done. I'm wondering what is the best way to layout a table of invoices which can have one or more tasks for each invoice. So far the invoice consists of: Invoice Table | InvoiceNumber | Department | DateOfBilling | Now, I need to somehow store the jobs associated with that...

cfquery type interface for C# asp.net

Hello, I really liked the cfquery in coldfusion and I'm wondering if anyone has attempted to write something like it for asp.net/C#. Or, does anyone know how they do it in cf with Java? I'd like an interface to my database that is similar QueryResult myObject = ObjectDatabase.Query("SELECT XXXXX","DataSource"); this.Var = myObject.Vari...

mysqli_error() expects exactly 1 parameter, 0 given

Hi, I am trying to get my head around mysql. Can someone tell my why this mysql query is not working? I am getting the following error: Warning: mysqli_error() expects exactly 1 parameter, 0 given in /home/freebet2/public_html/test.php on line 11 test.php <?php require_once($_SERVER['DOCUMENT_ROOT'].'/includes/db.ph...