query

PHP query join question.

if i have a table that looks like this: sample_id date sample_number 12 1-24-10 5 09 1-25-10 2 12 2-14-10 5 How can I join both (sample_id:12)'s ? sample_id:12 has a total of 10 sample numbers. ...

Ideas/tools/frameworks/... for an information source independent, interactive query system?

This is a conceptional question. I'm not (yet) familiar with the involved technologies, please bear this in mind. I'm thinking of developing a system that lets users make interactive queries, primarily for fault diagnostics. Users should be provided with the ability to start a "query" by entering some small peace of information. Let'...

Doctrine: Multiple (whereIn OR whereIn) query?

I'm having trouble crafting a fairly simple query with Doctrine... I have two arrays ($countries, $cities) and I need to check whether database record values would match any inside either. I'm looking for something like: ->whereIn('country', 'city', $countries, $cities) ... with 'country' being a WHERE IN for $countries and 'city' be...

how to insert a converted array to mysql? (Php)

I have converted a json data to array but now i wanted to insert it into my database i keep getting Array here is the code for ($i=0; $i<=$checking; $i++) { $catid = $ids[$i]; $catname = $names[$i]; $catapps = $apps[$i]; $caturl = $iconurls[$i]; $query = "INSERT INTO cat VALUES ('".$catid."','".mysql_real_escape_...

best way to run a periodic query in mysql

Hi all, In my Rails application I have a separate process (BackgroundRb) to delete all transactions which are not successful and it must be run after every five minutes. But in BackgroundRb, it runs a database check after every second though my query executes periodically at the specified time(after 5 mins). So my question is what is th...

SQL Query to Find tuples with maximum number of identical values

Any ideas how to implement the query: You are given a relation with N columns of the same type. Write an SQL2 query that returns the tuples having the maximum number of identical values. The query should have size polynomial in N. ...

Order database query results along a curve

i have a table of songs and their beats-per-minute values, and i would like to build playlists that follow a curve like this: ^ . . . | . . b | . . p | . . m | . . x--------------------> time i realize this is probably not possible in a single SQL statement, but i'm in...

mysql query normal relationship table vs concatenated realtionship table

I have a question about relationships between two tables. Let's say we have a table users, and links. users +++++++++ id name 1 name1 2 name2 3 name3 +++++++++ links +++++++++ id link 1 link1 2 link1 3 link1 +++++++++ Now the normal way to link these two is with a name_links table. For example: name_links ++++++++++++ uid ...

Creating subquery using IN

I have a question on making a good subquery for this problem Let's say we have a table users, and links. users +++++++++ id name 1 name1 2 name2 3 name3 +++++++++ links +++++++++ id link 1 link1 2 link1 3 link1 +++++++++ And lets say i have a relationship table like this name_links ++++++++++++ uid lid 1 1,3 2 1,2,3...

Problems calling MySQL stored procedures from C API

Hello, I have a problem calling a stored procedure on my MySQL server using the C API. I use mysql_query(&handle,"CALL myprocedure") but the function fails (returns 1) and error lookup gives the following message "Procedure myprocedure can't return a result set in the given context." I even tried to use mysql_real_query insted, but no ...

mysql problem: populate table from another table but referencing ID instead of name

Hi, I'm now trying to populate my 'testMatch' table (below) with data from my 'summary' table: TESTMATCH TABLE +------------------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +------------------+--------------+------+-----+---------+-------+ | match_id | int...

Convert struct to query Coldfusion

Wondering if anyone can assist I am utilizing some code from RIAForge which integrates with the Last.fm api... One of the methods outputs as a struct, but I would like to modify the code so it outputs as an array, am unsure of how to do this.. Currently the code is like this <cfscript> var args = StructNew(); var returnStruct = Str...

MySQL: value based on conditions

I have a MySQL query where I would like it to have a pseudo column returned which is based off of: If columnW does not equal 0, it should be 1 BUT If columnX does not equal 0, it should be 2 BUT If columnY does not equal 0, it should be 3 BUT If columnZ does not equal 0, it should be 4 Hopefully that makes sense. My SQL isn't good en...

Including calculations on related data in an ActiveRecord query

Let's say I have some models: User, Post, and Vote. A user has many posts and a post has many votes. Votes can be either an up vote or a down vote (stored as a boolean). What I am considering is the best way to do queries like these: All users, and the total number of up votes they've received. All users, and the post that has received...

[PHP | MySQL] multi-page forms and SESSIONS vs HIDDEN form data

I'm working on a 2 page form that POSTs a query to a database. Read-only, no writing. None of the information is confidential, nor will it every be. The site must be 100% non-JS compliant, so Ajax and the like are not available. All I got is PHP, baby! FORM-2's content is dependent on a fraction of the data in FORM-1, but ALL of the da...

Django queries: how to filter objects to exclude id which is in a list?

How can I filter in a query so the result excludes any object instances with ID belonging to a list? Lets say I have: object_id_list = [1, 5, 345] MyObject.objects.filter(Q(time__gte=datetime.now()) & Q( ... what to put here? ... )) Something in the style of "SELECT * FROM ... WHERE id NOT IN (...)" ...

CreateAlias and NHibernate joins on classes w/ no mapped relationship

I'm beginning to wonder if I am in fact too dumb to use NHibernate. I'm currently using FluentNHibernate to create simple db mappings and that's worked well for us. When dealing w/ our various classes in isolation, we're able to read and write, perform updates, etc. to all of those classes. My problem however is in trying to build up ...

How Can I Put Meta_Compare in the Database-Query? [Wordpress]

or something like > current date <?php $currentdate = date("Y-m-d G:i:s", $timestamp); $querystr = " SELECT * FROM $wpdb->posts LEFT JOIN $wpdb->postmeta AS term ON( $wpdb->posts.ID = term.post_id AND term.meta_key = 'vst_ort' ) LEFT JOIN $wpdb->postmeta AS course ON( $wpdb->posts.ID = course.post_id AND course.meta_key = 'vst_date' ) ...

How to draw two different possiblity of query tree for the example? in ddbms

select topic from book b, share s, stall st where b.b#=s.b# and st.store#=s.store# Hi friends, i am trying to draw query tree i dont know how to draw query tree for above example. can you help me in that. thanks in advance ...

Importing multiple records from sqlite db iphone sdk

I need some help! Please. I am trying to develop a very very simple application, basically just a simple book reader. Ideally, the first view would be a uitableview listing the names of chapters, then selecting the row would take you to a detail view that has the chapter which is broken up into segments. Note the segments are actually th...