mysql

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...

mysql split search string by space and push into query

The search query is: "product1 prod2 prod4" I need to make the mysql SELECT * FROM tableprod WHERE (prod LIKE '%product1%' AND prod LIKE '%prod2%' AND prod LIKE '%prod4%') using the mysql_real_escape_string for the input query... ...

How to use query results in another query?

I am trying to write a query which will give me the last entry of each month in a table called transactions. I believe I am halfway there as I have the following query which groups all the entries by month then selects the highest id in each group which is the last entry for each month. SELECT max(id), EXTRACT(YEAR_MONTH FROM date) as y...

Error while invoking MySQL Stored procedure(that returns resultset) from Rails 3

I am invoking a stored procedure (MySQL) from my model. This stored procedure returns a resultset, but i get this error... Mysql2::Error: PROCEDURE loqly.sp_venue_nearby_with_questions can't return a result set in the given context:.... Here's the rails code i use - connection.select_all("call sp_some_proc()") I have trie...

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. ...

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 my table structure

I'm trying to make an address book. And have made my tables like this: CREATE TABLE `list_`.`contacts` ( `id` int(11) NOT NULL AUTO_INCREMENT, `user_id` tinyint(11) NOT NULL, `group` varchar(128) NOT NULL, `first_name` varchar(128) NOT NULL, `last_name` varchar(128) NOT NULL, `address` varchar(128) NOT NULL, `city` varchar...

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! ...

Installing MySQL system tables... ERROR: 1136 Column count doesn't match value count at row 1?

I was setting up a Rails 3 environment on my local machine with MySql5 following this tutorial: http://blog.openrain.com/2008/08/20/setup-ruby-and-rails-on-osx/. When I run the below command: sudo -u mysql mysql_install_db5 I get the following error. -------- Installing MySQL system tables... ERROR: 1136 Column count doesn't match ...

I'm completely stumped: checking two tables against eachother in MySQL query

I feel like I'm writing a word problem, but it's really puzzling me and I really hope someone here can solve it: I want to select one row from table A. Table A includes the attributes Name and Number. But before I finish the query, I want to check it against table B. Table B includes Name, Number, and the Username of the user. Based on ...

Slow MySQL Query

I have tried everything to make this query faster that I know of. Same engine for every table, indexes on all the fields which are used for joins, order by or where clauses. The problem seems to be tables aam and ag are not using an index despite there being indexes available. Query: SELECT DISTINCT `a`.`id`, `a`.`full_name`, `a`....

MySQL coding question.

How would I check for a number like zero 0 in MySQL for example does user equal zero 0? Which one if any is the correct one? AND user = 0 AND user = '0' AND user = '" . 0 . "' ...

MySQL inclusion/exclusion of posts

This post is taking a substantial amount of time to type because I'm trying to be as clear as possible, so please bear with me if it is still unclear. Basically, what I have are a table of posts in the database which users can add privacy settings to. ID | owner_id | post | other_info | privacy_level (int value) From there, users c...

error in sql query

I am writing an query in sql and getting an error: Invalid use of group function What does it mean? In my query, where clause is given below: select c.name,s.contact,s.number from list c , senior s where c.id = s.id AND c.name = 'Abg' AND c.state ='qw' AND MIN(c.dob); Basically, I have 2 files and I need to find the younger custome...

mysql query on dob

If DOB is given in this porder- 1853-03-12 , then how do we find the youngest person from table bases on this type of data. If the year is same but month is different for 2 persons. I tried MIN(dob)- it gives me the oldest person and When I tried MAX, it gives me nothing. ...

Format for query condition

Hello, The code below is part of a query. I seem to have the format wrong for the part of the code that says AND ON C2.loginid = S2.loginid. What format should I use? Thanks in advance, John LEFT JOIN ( SELECT S2.loginid, COUNT(1) AS total FROM submission S2 INNER JOIN comment C2 ON C2.submissionid = S2.submissioni...

Most efficient way to find something recursively in a table?

I have a table users with the following columns id INT PRIMARY username target dead target contains an id of another user in the same table. All users start out with dead as 0. If dead is 1, then that means they're dead. As time goes on, dead can change, but target column will always stay with whatever it started with. If a user dies...

MySQL Ordering Lists Question

Hi All, I have the following code: SELECT q21coding, COUNT(q21coding) AS Count FROM `tresults_acme` WHERE q21 IS NOT NULL AND q21 <> '' GROUP BY q21coding ORDER BY Count DESC It brings back the following: q21coding Count Difficulty in navigating/finding content 53 Positive comm...