sql

Many to many query with a count of condition > 0

Hi everyone, I have 3 tables: Emails Foo EmailFoos (The many to many join table) Foo can be complete or not. I need to find the set of emails where the count of completed foos > 0 (and the inverse, but I can probably do that ;) I tried something like: SELECT e.id, e.address, count(l.foo_id) as foo_count FROM emails e LEFT ...

[SQL] How can I check for a certain value in all aggregated rows?

Suppose I have three tables: user, group and xref, a table that gives them many-to-many RI. I might want to see how groups each user belongs to: select user.user_id, user.user_name, count(*) as group_count from user inner join xref on user.user_id = xref.user_id inner join group on group.group_id = xref....

Connect to SQL Server from Microcontroller (Arduino or Fez with .Net Micro Framework)

I'm looking for examples, tutorials, or just "this+this+this should work" for reading from and writing to a SQL server (2008) from a microcontroller such as the Arduino board. I've also looked at (and will probably go with) devices with the .Net Micro Framework such as the Fez Cobra. The Micro Framework does not include ADO. I'm sure t...

SQL UNION query not working

here is my current queries: 1 SELECT FilteredInvoice.accountidname, FilteredInvoice.createdon, FilteredInvoice.createdon AS sort_date, FilteredInvoice.duedate, FilteredInvoice.invoicenumber, FilteredInvoice.statecodename, FilteredInvoice.totalamount_base, CONVERT(datetime, NULL) A...

MySQL Query Multiple Joins with Incorrect Results

I have 3 tables structured like so: activity table: activity_id, user_id, type, date reviews table: review_id, activity_id, fishery_id, review, date updates table: update_id, activity_id, update, date I want to call the all the reviews and updates which are linked to a user by the activity table however this query retu...

MySQL Error Code: 1005

I am trying to add foreign keys to my table but receiving this error. Error Code: 1005 Can't create table 'william.#sql-88c_3' (errno: 150) I have 3 tables. employee, client and Contract. employe [employee_no PK] , Client[customer_no PK] contract [contract_no PK] I want to have Foreign keys for contract as contract [contract_no PK, empl...

Parse a string before the Last Index Of a character in SQL Server

I started with this but is it the best way to perform the task? select reverse( substring(reverse(some_field), charindex('-', reverse(some_field)) + 1, len(some_field) - charindex('-', reverse(some_field)))) from SomeTable How does SQL Server treat the multiple calls to reverse(some_field)? Besides a ...

Where can I find a good jdbc-odbc bridge driver?

I do data conversions, and I am constantly connecting to a variety of different DBMS'. Certain DBMS' do not have JDBC drivers (MsAccess for example). Sun's JDBC-ODBC bridge driver was meant as a short term solution when JDBC drivers weren't widely available, and because of that, it is lacking functionality and is pretty buggy. I am to...

Pointers to tables in SQLite

Say I have a table of apples (apple_id). And for each apple I have a history of its weight over time. How to structure it so that every time an apple is added, an associated table is created with its weight history? Having only one table of weight history for all apples (apple_id,age,weight) seems like a performance drain when looki...

Sqlite, SQL: Using UPDATE or INSERT accordingly

Basically, I want to insert if a given entry (by its primary key id) doesn't exist, and otherwise update if it does. What might be the best way to do this? ...

How to convert MySQL datatype names into regular expressions using php?

Is there a php function to get regular expressions able to check if an input fits a certain MySQL data type? In example: $foo = get_regex_for_data_type("int(10) unsigned"); echo $foo; would return something like: /^[0-9]{1,10}$/ ...

Help with MySQL query synatx

I want to insert a row of data into a table with five columns (this table joins members and games); four of the five columns are known, while the fourth, rank, has to be dynamically calculated: wishlists(id (int, pk), memberid (int, FK), gameid(int, FK), rank (int), createdat(timestamp) ) INSERT INTO wishlists (memberid, gameid, rank) ...

Weekly summary table; how to reference the time dimension

We're thinking about adding a weekly summary table to our little data warehouse. We have a classic time dimension down to the daily level (Year/Month/Day) with the appropriate Week/Quarter/etc. columns. We'd like to have the time key in this new weekly summary table reference our time dimension. What's the best practice here—have the ti...

Call a WCF Service from a SQL CLR procedure in C#

I'm trying to call a WCF Service from a SQL Stored Procedure written in C#. I saw various posts or questions on about the same topic : http://stackoverflow.com/questions/3502343/calling-a-wcf-service-from-sql-clr-stored-procedure http://stackoverflow.com/questions/751500/sql-clr-stored-procedure-and-web-service But there's something I ...

Oracle debugging techniques

I don't know where error information goes when a trigger doesn't work correctly. My tool for writing triggers has been Oracle's Sql Developer tool, and my knowledge of how to debug it is pretty much nonexistent. What are some pointers for being able to find useful information about things happening "behind the scenes"? Also, are the...

sql join syntax

I'm kind of new to writing sql and I have a question about joins. Here's an example select: select bb.name from big_box bb, middle_box mb, little_box lb where lb.color = 'green' and lb.parent_box = mb and mb.parent_box = bb; So let's say that I'm looking for the names of all the big boxes that have nested somewhere inside them a litt...

does parentheses influence in this mysql results?

hello, i was trying to run this query: ( (SELECT * FROM (SELECT * FROM `users` WHERE `access_level` > 0) AS `search_subject` WHERE (BINARY `username` = ?)) UNION (SELECT * FROM (SELECT * FROM `users` WHERE `access_level` > 0) AS `search_subject` WHERE (BINARY `username` = ?)) ) LIMIT 5 but got an error because of the sur...

MySQL IN with LIKE

How would I use a IN table with like? So that I could use % in them? By in I mean: SELECT fields FROM table WHERE age = "50" AND name IN ("tim", "bob", "nancy", "john"); I already tried: SELECT fields FROM table WHERE age = "50" AND name LIKE ("2010-09-17%", "2010-09-16%") But it gave the error "Operand should...

SELECT from nothing?

Is it possible to have a statement like SELECT "Hello world" WHERE 1 = 1 in SQL? The main thing I want to know, is can I SELECT from nothing, ie not have a FROM clause. ...

MySQL Query Count Problem

I'm trying to count my comments and there replies but I can't seem to get it right. Here is my query so far. SELECT posts_comments.*, users.* (SELECT COUNT(*) FROM posts_comments WHERE parent_comment_id >= 1) FROM posts_comments LEFT JOIN users ON posts_comments.user_id = users.user_id WHERE post_id = '" . $post_id . "' AND parent_c...