query

Record that is related to all records of other table in SQL

Let's say we have three tables in a relational database: Person {id, name} Obstacle {id, name} Person_overcomes_obstacle {person_id, obstacle_id} I want to write a query that tells me if at least one person has overcome all obstacles. Ideas? ...

Is it possible to structure a SQL query to automatically create a table if it doesn't already exist?

I'm a complete SQL novice, and I'm trying to accomplish the following (pseudo-code) with a single query: if (a table named "config_data" does not exist) { create a table named "config_data" } if ("config_data" has no rows) { add a row to "config_data" with some default data } return all rows in "config_data" How would I go about it?...

Using select_related and extra clause

I'm trying to achieve some extra select on a queryset and wants to add the needed table to the pool of tables in the query using the select_related method in order to benefit for the '__' syntax. Here is an example with simple models : from django.db import models # Create your models here. class testA(models.Model): code = model...

Creating a simple join on a table with django

Hi, I have a data model in django called MainData which was created on top of a table called "my_data". I want to perfom a simple calculation on top of this table via django API. The query is as follow: select main.id, sum(main.num - secondary.num) as result from (select * from my_data where some_value >...

MySQL Transaction From PHP

QUERY 1: $link = mysql_connect('localhost', 'root', ''); mysql_select_db('rems', $link); mysql_query('SET AUTOCOMMIT=0; START TRANSACTION', $link); mysql_query('DELETE FROM admins WHERE admin_id=4', $link); mysql_query('ROLLBACK; SET AUTOCOMMIT=1', $link); QUERY 2: $link = mysql_connect('localhost', 'root', ''); mysql_select_db('rems...

NHibernate query against nested class

I'm using NHibernate. I have a class which has a nested type. Is there any way, using NHibernate, to query against the nested type, asides from using a native SQL query? Nested classes are not allowed in HQL currently. EDIT: The outer class has an IList of nested class instances. ...

How to add zeros in front of a text field in an access table.

Hi, I have an access table with a text field. It has alpha numeric values. But i want all values to be minimum 3 digit. so i want to add zeroes in front of all single or two digit values . 5 must become 005 89 must become 089 how do i write a query to update all values in the table. thanks tksy ...

Help on a SQL Query

In a previous Post, I was doing a very simple database with 3 tables "doctor", "patient" and "visit". I've tried to make it more realistic and included now a many to many relationship between "doctor" and "patient". "visit" is the table resulting in this n-m relation. I assume the following simple structure for my table : doctor - idD...

LINQ to SQL many to many int ID array criteria query

Ok this should be really simple, but I am doing my head in here and have read all the articles on this and tried a variety of things, but no luck. I have 3 tables in a classic many-to-many setup. ITEMS ItemID Description ITEMFEATURES ItemID FeatureID FEATURES FeatureID Description Now I have a search interface where you can select a...

Update mySQL table based on row=column name

A little background so you understand what I'm trying to do. I am making a page that takes two user input products and checks to see if they are compatible with one another. This is an n+1*n mySQL table because there are n products. The table looks like name a b c d e a b c d e I already know that every product is comp...

SQL Updated since last visit column

I'm working with SQL Server and I'm pretty new to SQL in general, so if this is a very trivial question, please bear with me. I have a table in a database with a datetime field representing some timestamp. When extracting the table via a SELECT statement, I would like to have a column of True/False representing whether or not the row ha...

Combine three tables into one, or too many columns?

I am tracking clicks over three time periods: the past day, past week and past month. To do this, I have three tables: An hourly table, with columns link_id, two other attributes, and hour_1 to hour_24, together with a computed column giving the sum A weekday table, with columns click_id, two other attributes, and day_1 to day_7, toge...

Querying multiple tables

Hi there. Following on from my query yesterday, I've restructured my recipe database as follows: categories cid | category_name 1 | desserts 2 | cakes 3 | biscuits recipes id | recipe_name 1 | black forest cake 2 | angel cake 3 | melting moments 4 | croquembouche 5 | crepes suzette ingredients iid | ingredient_name 1 ...

Help: Optimize this query in MySQL

This is my tables, the AUTO_INCREMENT shows the size of each: tbl_clientes: CREATE TABLE `tbl_clientes` ( `int_clientes_id_pk` bigint(20) unsigned NOT NULL AUTO_INCREMENT, `str_clientes_documento` varchar(255) DEFAULT NULL, `str_clientes_nome_original` char(255) DEFAULT NULL, PRIMARY KEY (`int_clientes_id_pk`), UNIQUE KEY `st...

Monitoring the progress of an SQL query in SQL SERVER

Hello, I saw a similar question which asked how to monitor the progress of a backup / restore operation: http://stackoverflow.com/questions/152447/is-there-a-sql-script-that-i-can-use-to-determine-the-progress-of-a-sql-server-ba I would like to know if there's a similar query / way to see how much time the query has left until it will...

Restrict querying for senders to a certain package

I know there's SOUL. But perhaps Pharo can do the following without any additional packages: How can I restrict searches for senders and implementers to a certain category? Like: I want to see all senders of compile: in OmniBrowser. More generally, how would you go and find the spot where compilation is invoked from OmniBrowser? (I roug...

Sql query join nearest date

I have a sqlite query that I'm trying to write. I have two tables: TableA (sales): id sales date TableB (goals): id goal date I'm selecting from TableA like this: SELECT id,sales,date FROM TableA Now to the "tricky" part. I need to join TableB to the query because I need the goal field in TableB for each row in TableA. TableB only co...

How do I improve SQL Server query performance when doing a LIKE over many columns.

My query needs to do a LIKE search over 3 columns. SELECT * FROM Monkeys WHERE [Name] LIKE '%pete%' OR [Desc] LIKE '%pete%' OR [Info] LIKE '%pete%'; I am looking to improve the performance of this query. I can't use full-text catalogs, just simple tables. There are about 200,000 rows (SQL Server 2008 database) and it takes 3 to 6 sec...

query to count words SQL lite 3

Is there a way to count words in a text string? I'm using SQL lite 3 and I'm trying to write a query that takes a bunch of long strings of text, and counts the number of words in each one. I also want to ignore html tags (or anything between carats) such as paragraph tags, break tags, etc. So when I run a query selecting text from the ...

SQL 2000 Set Query

Hi, I have a SQL 2000 server with a database (ITinventory) and a table which is also called ITinventory. I would like to create a query which will look at the field 'Status', if the status is 'disposed' then I would like to set a 'location' field to 'disposed'. Many thanks ...