sql

check field1 and field2 from single table

Hello, In SQL: I want to check. From single table, if(field1 = 1 and DATE_SUB(CURDATE(),INTERVAL 7 DAY) <= field2) then return count(*) else return "false" thanks v.srinath ...

Can this MySQL db be improved or is it good as it is?

In a classifieds website, you have several categories (cars, mc, houses etc). For every category chosen, a hidden div becomes visible and shows additional options the user may specify if he/she wishes. I am creating a db now, and I have read some articles about normalization and making it optimized etc... Here is my layup today CATEGO...

Finding One record from table having unique PK and duplicate FK

I want one record from a table having unique Primary Key and duplicate Foreign Key Please see attached image below Thanks ...

How do I search for names starting wih A in MySQL?

hi, I have a question that how can we use SELECT for searching the name which start with 'A' in MySQL table? thanks ...

help required with Sql query

I have a problem , got three Tables Table A ID Employee 1 1 2 2 3 3 Table B Id EMployee HoursWorked HoursCode 1 1 10 Basic Hours 2 1 20 Holiday Pay 3 2 10 ...

is there standard sql that works in all database

As seen below the syntax is different for different Database .Isnt there a standard way that works in all Databases. Is there any tool to convert any sql to any sql SqlServer2005: CREATE TABLE Table01 ( Field01 int primary key identity(1,1) ) Sqlite: CREATE TABLE Table01 ( Field01 integer PRIMARY KEY AUTOINCREMENT NOT NU...

Wrong number of database records is output by a Java program

Hi, I have a table in mySQL and has 3 line which has name ,address,Telephone,Age,Charge. in two of them the names are "Adam" and the last row is "Abas" ,i don't know that why it prints in the console like this,please help me thanks! Statement s; int s4,s5;String s1,s2,s3; List<InfoClass> clientList = null; try { ...

MySQL linking tables; some final issues

Firstly I want to thank all of you who have helped me understand Normalization and how I should build up my database. Now, I have some final issues left... How does LINKING of tables actually work? Say you have three tables: CATEGORY TABLE: cat_id (PK) -> 1 cat_name -> cars CATEGORY_OPTIONS TABLE: cat_opt_id (FK) -> 1 cat_id (FK) ->...

Why is this SQL script failing?

Hi, I'm trying to run a SQL script against SQL Server 2005 as part of the set up for my integration tests. The script works perfectly fine if I execute it from within SQL Server Management Studio. However, when executing programmatically, this part of the script that enables full-text search refuses to work: -- lots of tables and index...

Selecting 5 rows from a table, but one row is specifically specified.

Hi This seems possible, but at the same time I am wondering if it actually is possible. I have a table {users}. I want to pull 5 rows from that table, but at the same time, I want to specify one row. The closest sql statement I get is: SELECT u.id, u.full_name, u2.id, u2.full_name FROM users u JOIN users u2 ON u2.id !=...

Is order by clause allowed in a subquery

Is there any reason why or why not you should do an 'order by' in a subquery? ...

Query sql on string

hi all, I have a db with users that have all this record . I would like to do a query on a data like CN=aaa, OU=Domain,OU=User, OU=bbbbbb,OU=Department, OU=cccc, OU=AUTO, DC=dddddd, DC=com and I need to group all users by the same ou=department. How can I do the select with the substring to search a department?? My idea for the s...

MySQL Subquery returning incorrect result?

I've got the following MySQL query / subquery: SELECT id, user_id, another_id, myvalue, created, modified, ( SELECT id FROM users_values AS ParentUsersValue WHERE ParentUsersValue.user_id = UsersValue.user_id AND ParentUsersValue.another_id = UsersValue.another_id AND ParentUsersValue.id < UsersValue.id ORDER ...

Using the model clause to expand dates

I have several different types of data involving date range that I want to merge together, but at the same time broken down by day. So a 3 day piece of data would result in three rows: start primary_key start+1 primary_key start+2 primary_key I've been playing around using the model clause of the select statement in 10g and was l...

SQL: How to select elements in a rectangle range from a large continuous matrix? **UPDATED**

I'm having a hard time working out the following problem efficiently. I have a 15000x15000 xy matrix. I'm storing element locations in this matrix by defining a x,y coordinate for the element. I want to display a part of the matrix in a so called viewport. The viewport dimensions are e.g. 1600x1000 Consider the following db structure: ...

Referring to dynamic colums in a postgres query?

Let's say I have something like this: select sum(points) as total_points from sometable where total_points > 25 group by username I am unable to refer to total_points in the where clause because I get the following error: ERROR: column "total_points" does not exist. In this case I'd have no problem rewriting sum(points) in the where ...

Debug problem with asp.net VS2005

hi, I'm having troubles with an asp.net 2.0 application that I took over from other developers (meaning I don't really know much of the code). It is throwing an unhandled exception, but I cannot get any source info where exactly the exception occurs, and debug stepping through the source suddenly ends with the only option of showing dis...

Using Regex in SQL Server, I couldn't solve the following problem.

Hello all, I have strings like that OPEN SYSTEMS SUB GR (GM/BTIB(1111)/BTITDBL(2222)/BTVY(4444)/ACSVTYSAG) and I need to extract 2222 from it. What I was doing is this on the GROUPS String: SUBSTRING(GROUPS, CHARINDEX('(',GROUPS, CHARINDEX('(',GROUPS, CHARINDEX('(',GROUPS,0)+1)+1)+1, 4 ) AS GroupNo However I see that it is no...

Reducing the recordset where a particular field has similar data. (MySQL)

I have two tables, 'discussion' and 'discussion_responses'. A unique ID from 'discussion' is used in 'discussion_responses' to identify the response to the original post in a forum. I created the following query to extract the posts that have NEW replies, but are NOT linked to new topics. Both tables have a field for the date added and '...

MS Visio Category relationships to SQL Server

I'm using MS Visio to model a database and part of the model contains Transaction categories - the parent table has a transactionId, timestamp, amount, and transactionType. There are three child tables - cheque, bank transfer, and credit card, all related to the parent by transactionId. Is there a specific way this kind of relationship...