sql

PHP - SQL query Syntax Error

I'm having a hard time finding the error that exists in my script. Can anyone help me spot it? case "process_movie_order": // handle POST if ($_POST) { //Drop "order" column and Re-ADD it to reset ID #'s $droppedresult = mysql_query("ALTER TABLE videos DROP COLUMN order"); $add...

SQL: How do I loop through the results of a SELECT statement?

How do I loop through the results of a SELECT statement in SQL? My SELECT statement will return just 1 column but n results. I have created a fictional scenario below complete with the Pseudo code of what I'm trying to do. Scenario: Students are registering for their classes. They submit a form with multiple course selections (ie. s...

Strange behaviour of JOIN

Hi all, I have a strange problem with my query trying to join 3 tables. The tables descibed: 2 similar tables like this (entr_es): Field Type Null Key Default Extra espid int(11) NO PRI NULL auto_increment haslo text NO MUL NULL kat int(11) NO NULL The second table looks the same, except the first colum...

How to distribute SQL Server applications?

I have a VERY simple C# Winforms project that I made using Visual Studio 2010. It uses SQL Express 2008. This is my first time using SQL, so I wanted a hands-on approach to learning SQL, and this project allowed me to do that. I want to post my project on my website for people to see. However, I have stored procedures, constraints, and ...

MySQL - Searching with UNION ALL and GROUP BY

SELECT p.id, p.title, p.uri, 'post' AS search_type FROM `posts` AS p WHERE title LIKE "%logo%" UNION ALL SELECT p.id, p.title, p.uri, 'tag' AS search_type FROM posts AS p INNER JOIN post_tags AS pt ON pt.post_id = p.id INNER JOIN tags AS t ON pt.tag_id = t.id WHERE t.title LIKE "%logo%" UNION ALL SELECT p.id, p.title, p.uri, 'c...

MySQL SELECT from a group of tables retrieved from INFORMATION_SCHEMA

Hey all. I've got the following set of tables which is variable and adds up every day: data-2010-10-10 data-2010-10-11 data-2010-10-12 data-2010-10-13 And so on. All the tables have the same structure and what I'd like to do is select stuff from all tables at once. I'm unable to use a MERGE table since I'm running InnoDB. Anyways, I'm...

MS access: Export query output to excel and auto create Pie Chart in excel

Folks, i want to generate ( or trigger) query output from MS Access to MS Excel. I want either embed code within SQL query which generates .xls or write external code. Now i am generating report using "export" option but i want to automate export. -Vijay ...

How large can the array passed to SQL where column_value IN (Array) be?

I am writing some code that will lookup for unique id's in a table with over 60,000 rows for the ones that are in an array using mysql_query("SELECT * FROM users WHERE unique_indexed_user_id IN('".join("', '", $array)."')") ; the amount of this array is not limited to the end user so they might end up selecting a large array. thus I...

How to insert values into an MYSQL-DB via subselect?

Hey folks, In oracle-db it is possible to insert values from table A to table B like Insert into table_a values Select * from table_b where ID = 10 ; If the structures are the same. How can I do this in MYSQL? My Editor gave me an sytanx-error. Thx 4 your answers! Greetz ...

query based on sql

Hi, I'm writing a query in SQL in which i have to find the youngest senior person from a data given to me. SSn DOB 22 1950-2-2 21 1987-3-3 54 1954-4-7 The data is in the manner. And I need to find the age first so that I can write the condition of senior customers which is age >50. Since I dont have age parameter, please sug...

Geolocation and Haversine formula

I am trying to create a basic web application that detects the users geolocation, queries a mySQL database, and returns all bus stops within say 5 kilometers. The GTFS feed including the Longitude and Latitude have been inserted into a mySQL database, and I found a example HTML page that provides the Longitude and Latitude of the browse...

age from dob in sql

In the sql query, I am getting problem in the where clause. I have a dob and ssn of people in a table. I need to find the youngest snr. customer. The age of youngest senior customer starts from 55. The data of DOB contains all the dob's of children,parent, senior customers. In the line "where" I have to write a condition that checks if ...

query in sql database

Hi, How do we find the top 2 most populated cities i.e where no. of customers are higher than any other.I only have the SSN of the customers. They are unique and I am thinking of counting them for a particular city and check if that is higher than any other city. ...

Checking if 1 item or more in a delimited string exist in another

Hi all, Which is the best way to check if 1 item or more of one delimited string exist in another? I'd like to pass 2 delimited strings to a UDF and get back TRUE if at least one item of the first delimited string exists in the second delimited string. delStr1="US,FR,DE" delStr2="GB,DE,CA,IT,PL" delStr3="CN,DK" CheckDelimitedStrin...

PostGIS: bounding box of a multipolygon

SELECT id, ST_Box2D(areas) AS bbox FROM mytable; In this example, the table "mytable" contains two columns: "id" is the unique id number of the row and "areas" is a geometry field containing one MULTIPOLYGON per row. This works fine for multipolygons containing only one polygon, but some rows have polygons very spread apart, hence t...

storing multiple formats in a table

So here's the basic problem: I'd like to be able to store various fields in a database. These can be short textfields (maybe 150 characters max, probably more like 50 in general) and long textfields (something that can store a whole page full of text). Ideally more types can be added later on. These fields are group by common field_gro...

Help with sql statement

I want to guarantee that a token is assigned to an order. All available tokens are inside the Token table and each token can ONLY be assigned to 1 order. Here is the sql I came up with: SET XACT_ABORT ON; BEGIN TRANSACTION -- Reserve token. SELECT @token = token, @tokenId = id FROM Tokens WITH (UPDLOCK) WHERE taken = 0; -- Take token. ...

In php how to display mysql results?

I have a mysql table in which I keep e-mail addresses. The structure is as follows: id || email However, how do I actually output those e-mail addresses, separated by commas, in php? Thanks in advance for your help! ...

Why are CTE's unable to use grouping and other clauses?

I recently learned about Recursive Common Table Expressions (CTE's) while looking for a way to build a certain view of some data. After taking a while to write out how the first iteration of my query would work, I turned it into a CTE to watch the whole thing play out. I was surprised to see that grouping didn't work, so I just replaced ...

django: datediff sql queries?

I'm trying to do the equivalent of the following SQL in Django: SELECT * FROM applicant WHERE date_out - date_in >= 1 AND date_out - date_in <= 6 I can do this as a RAW sql query, but this is becoming frustrating in dealing with a RawQuerySet instead of a regular QuerySet object as I would like to be able to filter it later in the code...