mysql

Wikipedia integration issue - need to finally sort this out 101

Sorry guys, I've been running a mock asking questions on how to integrate wikipedia data into my application and frankly I don't think I've had any success on my end as I've been trying all the ideas and kinda giving up when I read a dead end or obstacle. I'll try to explain what exactly I am trying to do here. I have a simple directory...

What is the best practice to count equal values in a database?

I have a fairly large mysql database and I would like to count all the equal values, to explain myself better: I have a country field which has several countries values (USA, UK, MEX, etc..) and I want to get the number of countries without duplicate (if I have 100 USA and 2 UK and 1000 MEX the result would be 3). The only way I could ...

Best way to test for duplicate keys in a database

This is more of a correctness question. Say I have a table with a primary key column in my database. In my DAO code I have a function called insertRow(string key) that will return true if the key doesn't exist in the table and insert a new row with the key. Otherwise, if a row already exists with that key it returns false. Is it better/...

Using DISTINCT and COUNT together in a MySQL Query

Is something like this possible: SELECT DISTINCT COUNT(productId) WHERE keyword='$keyword' What I want is to get the number of unique product Ids which are associated with a keyword. The same product may be associated twice with a keyword, or more, but i would like only 1 time to be counted per product ID ...

MySQL: Select Distinct from 2 different tables?

I have 2 different tables that each have a column called product_type. How can I get the DISTINCT values of product_type across both tables? Just to clarify, if both tables have a product_type of "diamond" I only want it returned once. Basically as if both tables where combined and I selected distinct product_type from it. Thanks!! ...

Workaround for MySQL limited TIMESTAMP range?

Does anyone know of a workaround for storing values outside of the range '1970-01-01 00:00:01' UTC to '2038-01-09 03:14:07' UTC in a MySQL TIMESTAMP field? ...

MySQL: select emails from one table only if not in another table?

I am going to build a table called donotemail that will contain the email addresses of people who ask to be removed from our email list. I have another table called users with an email column. How can I select all the emails from users but only if the email address is not in the donotemail table? Thanks! ...

How should I filter dates in MySQL?

I'm creating a set of "archive" pages that are specified by year and month. In my table I have a datetime field called posted. I want to select all rows that are in a particular month. I've thought of two solutions: (1) Use string matching: SELECT ... WHERE posted LIKE '2009-06%' (2) Use some MySQL extraction functions: SELECT ... ...

Pulling a column value from an Array of Table Names

Hello, The code below prints out all tables in a database called "feather" that contain "$entry" in a column called "site." Every table in "feather" has a column called "site." This code works great. However, I would like to add something. Every table in "feather" also contains a column called "votes_up." For each table that has "$...

Why not use MySQL's TIMESTAMP across the board?

If you need your web application to translate between timezones on a per-user basis, why not use TIMESTAMP across the board for all date/time fields? Consider that TIMESTAMP values are stored in UTC and converted to the timezone set for the connection when retrieved. I have asked this question on IRC, read the MySQL documentation, searc...

Difference between LIKE and = in MYSQL?

What's the difference between SELECT foo FROM bar WHERE foobar='$foo' AND SELECT foo FROM bar WHERE foobar LIKE'$foo' ...

MySQL error 1005 on table create -- wtf

My table definition: CREATE TABLE x ( a INT NOT NULL, FOREIGN KEY (a) REFERENCES a (id) ON UPDATE CASCADE ON DELETE CASCADE ) ENGINE = InnoDB; which produces the following error: ERROR 1005 (HY000): Can't create table './abc/x.frm' (errno: 150) What does this mean? ...

What's a good book for learning MySQL?

I want to get a book to learn mysql. I know some things like basic selecting and updating but not very much. I don't really want a cookbook style book but a book that will give me an fundamental understanding of how SQL actually works so I understand the code I am writing instead of just copy+pasting it. I like orielly books so I was con...

jdbc returns mySQL syntax error exception for a valid query

I user the java.sql.Statement.excecuteUpdate method to create a table and insert some values into the database through JDBC. However, it gives me MySQL syntax exceptions for no reason. I copied and pasted the same code into command prompt. it worked. I'm wondering why it's doing that?? ...

Sort through MySQL result to create multilevel dropdown menu

I am just puzzled here. Maybe because it's the end of the day, I dont know. Im using PHP to grab items from a MySQL db. I am just looking for some PHP help. I have the HTML and CSS done. Here is the basic structure of the db. Its a nested set btw. Imagine that my left and right values for the nested set have been sorted in MySQL already ...

INSERT SELECT in MySQL with superfluous aggregate column

I'd like to do an insert select where the select statement has aggregate columns for use by a "HAVING" clause, but where I do not actually want those columns to be inserted. A simple example: INSERT INTO table1 ( a ) SELECT a, MAX (b) AS maxb FROM table2 GROUP BY a HAVING maxb = 1 Of course, this won't work because there are a diff...

PHP - Code Almost Does What I Want it to

Hello, The code below echoes the following: Table Name 1 Table Name 2 Table Name 3 Table Name 4 "$entry": "votes_up for $entry in Table Name 4" I want it to echo this: Table Name 1: "votes_up for $entry in Table Name 1" Table Name 2: "votes_up for $entry in Table Name 2" Table Name 3: "votes_up...

Optimizing a simple query on two large tables

I'm trying to offer a feature where I can show pages most viewed by friends. My friends table has 5.7M rows and the views table has 5.3M rows. At the moment I just want to run a query on these two tables and find the 20 most viewed page id's by a person's friend. Here's the query as I have it now: SELECT page_id FROM `views` INNER J...

Repeating lines in Crystal Report

I'm working with MySQL connector and C#. Everything was ok until I got to the reporting part. There is no standard way to retrieve the data from MySQL to CrystalReport. So I read in this page that what I have to do is a XML file of a View created in MySQL then retrieve the data for Crystal Report. I dunno if you have done it but I am hav...

MySQL: Is it possible to JOIN the GROUP-BY'd results to two SELECTs?

Hi, I have two separate SELECT statements which are both GROUP-BY'd separately e.g.: SELECT x, y, z FROM a GROUP BY x SELECT x, n, o FROM b GROUP BY x I would very much like to JOIN these two SELECTs together to combine their columns, such as: SELECT x as x1, y, z FROM a GROUP BY x LEFT JOIN ( SELECT x as x2, n, o FROM b GROUP BY...