mysql

In MySQL will UNIQUE index act as fast lookup for varchar column?

If I have a column short_title in MySQL table and it is defined as UNIQUE, do I also have to add FULLTEXT for it to be searchable really fast? Or does UNIQUE already guarantee it will be searchable quickly (without full table scan)? Thanks, Boda Cydo ...

Agregate SQL query with maximun number of rows to take into account

My head is hurting trying to figure out a SQLquery. I have a table of vote data with team_id, ip_address and date_voted fields and I need to return a count of votes for each team_id but only count the first 10 rows per IP address in any 24 hour period. Any help will be greatly appreciated and may stop my head from pounding! ...

any way to view ALTER TABLE after its been executed? -MySQL

In the same way SHOW CREATE TABLE tblname; brings back what was previously executed, is there anyway to view the SQL of an ALTER TABLE query? please help? ...

refer to complex expression value in where clause

I have a query where I have a complex date expression as one of the columns. SELECT date_column + INTERVAL( complex_jimmy_jam ) DAY AS complex_date_calculation FROM table I want to refer to that column in the where clause WHERE complex_date_calculation < NOW() But mysql chokes on it. 1054: Unknown column 'complex_date_calcul...

[mysql] where query count result > 0

Hi all, I need to do a query like this: SELECT wposts.ID FROM posts wposts WHERE ( SELECT COUNT(ID) FROM surveys WHERE POST_ID = wposts.ID) > 0 but need it to be working ? ...

Converting String to Long ...in LINQ to Entity Framework using a MySQL adaptor.

I have a table with a column of type varchar where the majority of rows have numerical looking values, that is, each string contains nothing but the digits 0 through 9. +------+ | n | +------+ | 123 | | 234 | | BLAH | -- This row is an exception to the rule. | 456 | | 789 | +------+ In MySQL, this works: SELECT * FROM t WHERE n...

Access database variable in functions with PHP

I am fairly new to PHP and I have found that a lot of my functions require access to the database. The problem is I currently connect to the database in a file that I require at the top of every page like so: $db = new mysqli("localhost", "my_user", "my_password", "world"); The problem I find is then when I want to access it within a ...

database encoding problem? Double and single quotes being displayed w/ question marks

Old server db = MySQL v4.0.21 New server db = MySQL v5.0.45 I am moving an app to a new server, and I copied over the database. The app sends an agenda for the day and whenever there are double & single quotes " ', they show up as question marks ? Comes up like this on the server it was moved to ?The Horror of Race: HBO?s True Blood? ...

MySQL, C++: Need Blob size to read blob data

How do I get the size of data in a BLOB field in the Result Set? (Using C++ and MySQL Connector C++) In order to read the data from the result set, I have allocate memory for it first. In order to allocate memory, I need to know the size of the blob data in the result set. Searching the web and StackOverflow, I have found two method...

How do I do .find in MYSQL Select?

DELETE FROM mytable WHERE column1.find("has_this_word_somewhere") ? ...

Sorting by "last name" in MySQL when "full name" has periods in it

I found this nifty little order by condition that sorts strings of the type "First Last" nicely, even handling "First Van Damn" properly. "SUBSTRING(p.name, LOCATE(' ', p.name) +1) Now, I have some names in there like "Alfred E. Newman" and want the sorting to work properly for that name (ie it does not end up under E). Any help woul...

Connecting/Checking a MySQL database in C#

Can someone provide with me some code to connect to a MySQL database and check the whole of one column to see if it is less than 2? I've looked online and have found nothing which can help. Thanks so much, Lawrence ...

How to dump a single table in MySQL without locking?

When I run the following command, the output only consists of the create syntax for 'mytable', but none of the data: mysqldump --single-transaction -umylogin -p mydatabase mytable > dump.sql If I drop --single-transaction, I get an error as I can't lock the tables. If I drop 'mytable' (and do the DB), it looks like it's creating the ...

Keeping ORM with stored procedures

Hello, I am developing a Python web app using sqlalchemy to communicate with mysql database. So far I have mostly been using sqlalchemy's ORM layer to speak with the database. The greatest benefit to me of ORM has been the speed of development, not having to write all these sql queries and then map them to models. Recently, however, I'...

PHP How to check if you can afford it?

Hello. I have this: $scCost = $row["gpsc"]; mysql_query(" UPDATE member_profile SET points = points-$scCost WHERE user_id = '".mysql_real_escape_string($userid)."' ") or die(mysql_error()); That takes do the user´s points - scCost. How do i check if the user can afford it or not? So, if the user...

Suggestion on a replication scheme for my use-case?

I am working on an application that runs on multiple clients that talk to one main MySQL database. Additionally, we have a web application that uses the same MySQL database. Due to latency issues, all clients will have to run their own local MySQL database which should be a copy of the main MySQL database. The web application remains to...

MySQL - Duplicate elimination and Preserving Valuable Data?

Scenario : I have few duplicate contacts in a table. The duplicates are identified, I can just delete them but the problem is I don't want to lose the data the duplicate might have and the original don't. Any tips? Sample data : ID Name Email School Dupe_Flag Key 1 AAA a@a X 1 2 AAB JKL 1 3 BB...

MySQL: Invalid use of group function

I am using MySQL. Here is my schema: Suppliers(sid: integer, sname: string, address string) Parts(pid: integer, pname: string, color: string) Catalog(sid: integer, pid: integer, cost: real) (primary keys are bolded) I am trying to write a query to select all parts that are made by at least two suppliers: -- Find the pids of parts s...

Mysql auto fill field based on value of two other fields?

I know its possible to autoincrement values, but i was wondering if its possible to fill a field based on the value of two other fields. I have a table with the fields: CREATE TABLE pligg_links ( ... link_votes INT, link_reports INT, link_votes_total INT, ... ); Field link_votes_total should hold the value of field link_vote...

MySQL: Why doesn't this db creation script work?

For some reason, this MySQL fails: CREATE SCHEMA IF NOT EXISTS `partB` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci ; USE `partB`; CREATE TABLE Employees ( ssn CHAR(11), Name CHAR(30), mlot INTEGER, PRIMARY KEY(ssn)) ENGINE = InnoDB; CREATE TABLE Dept_Mgr ( did INTEGER, dname CHAR(20), ssn CHAR(11) NOT NULL, PRIMARY KEY (did...