Say I have these tables:
people(id, name),
cars(person_id, car)
and this query:
SELECT c.car
FROM people as p, cars as c
WHERE c.person_id = p.id
AND p.id = 3
I want the c.car column to take its name from the name field in the people table, like this (invalid SQL, just to illustrate):
SELECT c.car AS(SELECT name FROM people WHERE id = 3)
How do I do that?
I have been tasked to shrink a SQL server 2005 database. This ia a live database and is runing at about 35gb.
How do I shrink a database?
Can this be done while that database is live?
How big will that database bw when it has been shrunk?
Thanks in advance.
I have a MySQL table with a column called "priority". The column can have two values: high or low. I want to select 8 records from the table at random, but I want 6 of them to be high priority, and 2 of them to be low priority. If possibly, I would like to do it in one SQL statement. Is there any way to do two LIMITS in one query based on this kind of criteria?
This is my SQL:
SELECT `tbl`.*, 123 AS `test` FROM `tbl` GROUP BY `test`
It works when I run it directly in MySQL. But PDO says:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'test' in 'field list'
Why so? How to cure this problem? I'm using Zend_Db.
In sql server how difficult would it be to determine what procedures/functions no longer compile? In other words, if I scripted out alter statements for all procedures and functions in a database, I'd like to know which of these statements are going to fail?
I've been working on cleaning up a database I've inherited which has gone through years of changes and I'd like to what objects are going to raise errors when something tries to execute it.
I need to get all rows tha are valid, ValidDate is column that shows how long these database items are valid. I need to get only valid items from the database. How can I do that? I use SQL Server.
I have a SQL Query:
SELECT documents.*, t_rights.rights, documents_list.docs
FROM documents
INNER JOIN t_rights on t_rights.num=documents.type_right
INNER JOIN documents_list on documents_list.num=documents.document1
WHERE code_document=1 or code_document=1
In case if i have fields documents.document1 and documents.document1 with some value all works fine. But if this field empty i get empty query result.
Its possible make query like this with empty fields?
Hello,
I am after an SQL command to find units with no categories. Here are the tables:
Unit
id name
UnitCategory
id name
UnitCategoryIndex
id categoryid unitid
Thanks!
I am having string called '200_CFL_2010'. I wish to get the characters between _'s. I want the output as 'CFL'. I have to achieve it through SQL. Any idea please?
Hi,
Is there any application that will read a MySQL database table and generate a SQL script of INSERT statements (so that I can copy tables from one db to another db)? OR how can I transfer content from db1.table1 to db2.table2 where table1 and table2 is same.
Thank you.
i have a date (eg: 2010-04-17 ) i need the date of after 20 days from this date
How to get the date after 20 days i.e next month some date.
either in sql or in c#
I have an Information table with 3 colums tableName/FieldName/Value and its data like this:
TableName|FieldName | Value
Films |DateSortie |NULL
Films |Duree |NULL
Films |CodeLangue |NULL
Films |Documentaire |NULL
Could you show me a SQL statement to put data into the Value Field, please! Note that I also have table Films and its fields like data in FieldName field of the Information table
Thanks in advance
TNT
hello, im trying to delete a foreign key with the following syntax (5.0.45-community-nt):
alter table [table] drop foreign key [fk_name]
but I'm getting the folling error:
The table '#sql-5f8_9c' is full – 99543 ms
any ideas?
thanks!
i would like to force the textbox to immediately change the text to UCASE as soon as the user moves away from the field. is this possible?
the important thing is that this text will be used in a SQL query to update a table.
The last time I worked with Zend_Db I recall I used to write SQL Queries manually. I've been searching for some ORM application, but, since I read something like Zend_Db is also capable of doing so, I started to try it, but I can't find neither a good tutorial explain it or a good documentation.
I read something lake Gateway pattern and ModelMapper class but I can't figure it out.
Can someone shine my path? :P
I am running a query in SQL, and I need to select a minimum date that is not 0000-00-00. Is there any way to exclude this value and choose the next minimum date?
I'm reading a book about SQL.
In that book, I saw strange query below:
SELECT * into mycustomer from customer WHERE 1=2
In this query, what is "WHERE 1=2" ?
It says I ended this statement wrong when if I input it into sql plus with just the addition of ; it works perfectly. What am I doing wrong?
Statement statement = connection.createStatement();
statement.executeUpdate("delete from aplbuk MODEL = '"+ textField_4.getText() + "'AND year = '" + textField_1.getText() + "' AND Litres = '" + textField_2.getText()
+ "' AND ENGINE_TYPE = '" + textField_3.getText() + "'");
statement.close();
My code is SELECT COUNT(*) FROM name_list WHERE [name]='a' LIMIT 1
It appears there is no limit clause in SQL Server. So how do i say tell me if 'a' exist in name_list.name?
For clarification, are you able to use MySQL this way to sort?
ORDER BY CompanyID = XXX DESC
What I am trying to do is use one sql query to sort everything where X = Y, in this case, where CompanyID = XXX. All values where CompanyID is not XXX should come after all the results where CompanyID = XXX.
I don't want to limit my query but I do want to sort a particular company above other listings.
I need a SQL statement to retrieve records where it key (or any column) is in a associate table, for example:
documentId termId
4 1
4 2
3 3
5 1
This:
SELECT documentId
FROM table
WHERE termId IN (1,2,3)
...will retrieve any documentid value where the termid value is 1 or 2 or 3.
Is there something like this but return documentid values where the termid values are 1 and 2 and 3? Like an IN but with AND.
Hi
I have a table (lets say it has one column called 'colLanguage') that contains a list of skills and has a full text index defined on it. One of the entries in the table is 'c#' but when I search for 'c#' (using the following SQL) I get no results back.
select *
from
FREETEXTTABLE(tblList, colLanguage, 'c#')
Can anyone help?
Thanks
K