sql

MySQL - group rows in 4's

I have a product table like this: Product name , Affiliate ID , ProductCode a, 1, 1 b, 1, 2 c, 1, 3 d, 1, 5 e, 1, 7 f, 2, 4 g, 2, 6 I want to return first four products from each Affiliate ID. The 'ProductCode' column signifies the order in which the products were added, so can I use this column to sort my results. But I don't know ho...

Effect of style/format on SQL

Ignoring version, what are the best practices for formatting SQL code? I prefer this way (method A): select col from a inner join b on a.id = b.id inner join c on b.id = c.id a colleague prefers another (method B): select col from a inner join (b inner join c on b.id=c.id) on a.id = b.id I'd like to know if there is any difference...

SQLite : INSERT and ORDER in the same time

Hello ! I have a table with 25.000 rows (columns with strings). I would like to improve my select query. "SELECT name FROM table WHERE name LIKE 'something' ORDER BY name LIMIT 15" The database will be static. I would like to know if it's possible to order a column when I am inserting a row in my table and if it will reduce the time ...

Nhibernate question

Hi i create one table "TransactionLog". In that table,record is there, i open the sesson now i generate one query and i m trying to retrive records but still its not showing me Mapping file of Transaction log is ...

Searching data which spans through a lot of tables - design question

I have a structure of about 10 tables. This structure works great for data entry. However, I also need to preform complex and fast searches on that dataset. There are three approaches to this I can think of: Join all those tables in select. This is pretty slow and likely not a good approach. If it's relevant, database is Informix; I've...

SQL Table A Left Join Table B And top of table B

Hi All, Im working myself into an SQL frenzy, hopefully someone out there can help! I've got 2 tables which are basically Records and Outcomes, I want to join the 2 tables together, count the number of outcomes per record (0 or more) which I've got quite easily with: Select records.Id, (IsNull(Count(outcomes.Id),0)) as outcomes from...

What are views in MySQL?

What are views in MySQL? What's the point of views and how often are they used in the real world. I'm after a layman explanation please with a example if possible to aid my understanding! Thank you in advance ;-) ...

Update textbox value into sql

Hi..When im trying to update the textbox values into db.It throws me an exception "Invalid syntax near (value of the txtkey.text)" Can anyone Help SqlConnection con = new SqlConnection("server=server1;Database=testdb;User Id=dev;password=sqlad@2006"); SqlCommand com = new SqlCommand("insert into tbl_licensing(UserName,Co...

db2 special character 0x1A

Hi, how can I seach for a spezial character like "→" (0x1A). An example for my query is: select * from Data where Name like '%→%' I want to use instead of "→" somethoing like 0x1A I can't use any Java or C# Code. I just have SQuirrel to connect and send commands to the database. Thanks Stefan ...

How do I update records only if I find a duplicate or otherwise insert data?

In the code below there is a hash which contains records with fields like name, pid, type and time1. pid and name are repetitive fields which contain duplicates. I duplicate found update the fields which need modification else insert, here name and pid have duplicates (repetitive fields). The rest are unique. Also I have a unique field...

Sqlite db, multiple row updates: handling text and floats

Hi, I have a large SQLite database with a mix of text and lots of other columns var1 ... var 50. Most of these are numeric, though some are text based. I am trying to extract data from the database, process it in python and write it back - I need to do this for all rows in the db. So far, the below sort of works: # get row using sele...

How to know how many OR conditions are satisfied?

How can i know that which of my result has satisfied how many number of conditions/ SELECT [TITLE] FROM [M_TIPS] WHERE [TITLE] LIKE '%VALUE%' OR [TITLE] LIKE '%SQL%'; How to know that which of the result has satisfied only 1 OR condition and which of the result has satisfied both conditions. The number of condit...

UPDATE column from another column two tables away

Not that good with SQL yet but I'm learning. So I have 3 tables: tblOne(Id, Type) tblTemp1(Name, Type) tblTemp2(Id, Name) Basically, I want to update tblOne where the where it's 'Id' matches from tblTemp2, but than that also goes and grabs its 'Type' from tblTemp1 where the 'Name' matches. Can anyone help? ...

SQL: need only 1 row per particular timestamp

i have some SQL code that is inserting values from another (non sql-based) system. one of the values i get is a timestamp. i can get multiple inserts that have the same timestamp (albeit different values for other fields). my problem is that i am trying to get the first insert happening every day (based upon timestamp) since a parti...

MS Access 2010 Get column names

Hi guys, I need to get all of the column names of a table using vba or Access SQL and iterate through them for validation, does anyone have a solution to this, I have searched google to no avail. Any help much apriciated :) ...

Getting data for more than 1 categories in SQL Server

There are some categories and its products. But products is used for another categories. For example, There are "metal handles" categories and it is used for "metal handles" but at the same time it is used for "children handles". I should say them that you belong to "metal handles" but you could be in "children handles" too How do I cre...

RegEx for parsing SQL query in C#

I need to write RegEx in C# to parse SQL join query which is given as a string. Can somebody please help me because I'm new at this. Thanks a lot this is my problem: string query = @"SELECT table1.column1, table1.column2, table2.coulmn1, table2.column2 FROM table1 INNER JOIN table2 ON table1.column5 = table2.column5"; ...

How to get many rows based on several uniqueidentifiers?

I'm trying to make a select like this: DECLARE @ContentIDs VARCHAR(MAX); SELECT @ContentIDs = 'e28faa48-adea-484d-9d64-ba1e1c67eea3,8338A6DE-8CDF-4F52-99CE-62E2B107FF97' SELECT * FROM [Content] WHERE [ID] IN (@ContentIDs) It only returns the content with the first UNIQUEIDENTIFIER. How can I retrieve all rows? ...

Limiting query size with entity framework

this is a simple question (I think), but I have not been able to find a solution. I know with other types of queries, you can add a limit clause that makes the query only return up to that many results. Is this possible with an entity query? var productQuery = from b in solutionContext.Version where b.Prod...

How do you rewrite a query in PostgreSQL 8.3

Hey everyone, I'm pretty new to the SQL and need some help with a certain task. I have a query that is called by our Flex/Java code that joins multiple tables to get information. Upon running an Explain Analyze, I've seen that the query takes over 15 minutes which sometimes even times out if the site is under heavy traffic. What I am tr...