mysql-query

select thursday from date in mysql

How to select a day say thursday from a date in the mysql select query and use this day to select some other values in same table select id,music_id,contest_no,today,exp_date,start_hour,start_minute,start_ampm, DAYNAME(today) as chday from hit_music_content where exp_date>='2010-07-30' and today between '2010-07-30' and '2010-...

mysql query to display top 5 record then next record in after some week

mysql query to display top 5 record then next record in after some day say on friday ...

search in joint tables

I have four tables: cuisines(id, name); recipes(id, cuisine_id, name, picture); ingredients(id, name); ingredients_recipes(ingredient_id, recipe_id); the last table references the Many-To-Many relationship between recipes and ingredients. How can I select all cuisines which contain tomatoes (i.e. the cuisine has recipes which have ...

MySQL: Not unique table/alias: 'favourites'

Hello folks. The error I'm getting is: Not unique table/alias: 'favourites' I apologise for the reasonably intense query(!): SELECT code.id AS codeid, code.featured AS featured, code.title AS codetitle, code.summary AS codesummary, code.author AS codeauthor, code.date, code.challengeid, ratingItems.*, FORMAT((ratingItems...

how to find which field is duplicate

My table is having four fields in which two fields are unique. They are username and email for example. People register in the front end. I dynamically display the result of their registration using ajax. I am doing a single insert query. And if there is an error then i use the error number to find whether it is 1062(duplicate entry) or...

mySql sum a column and return only entries with and entry in last 10 minutes

heres a table, the time when the query runs i.e now is 2010-07-30 22:41:14 number | person | timestamp 45 mike 2008-02-15 15:31:14 56 mike 2008-02-15 15:30:56 67 mike 2008-02-17 13:31:14 34 mike 2010-07-30 22:31:14 56 bob 2009-07-30 22:37:14 67 bob 2009-07-30 22:37:14 22 ...

Using SQL to find the total number of customers with over X orders

Hey all, I've been roasting my brain with my limited SQL knowledge while attempting to come up with a query to run a statistic on my orders database. Table ORDERS is laid out like this: CustomerID ProductID (etc) 1 10 1 10 1 11 2 10 4 9 Each purchase is recorded with t...

Using SQL to find the total number times a product has been bought in one query

Hey all, I'm trying to find the most optimal way to return a recordset containing a list of all products that have been bought by customers and how many of each have been sold. Table ORDERS is laid out like this: CustomerID ProductID (etc) 1 10 1 10 1 11 2 10 4 9 This...

LIMIT ignored in query with GROUP_CONCAT

Hello, I need to select some rows from second table and concatenate them in comma-separated string. Query works well except one problem - It always selects all rows and ignores LIMIT. This is part of my query which gets that string and ignores LIMIT: select group_concat(value order by `order` asc SEPARATOR ', ') from slud_data ...

Help with a joined query (MySQL)

Hello can anybody see why this query fails? SELECT A.idAd, A.ads_in_Cat, A.title, A.currency, A.price, A.in_dpt, A.description, A.featured FROM ads A LEFT JOIN featured F ON F.ad = A.idAd INNER JOIN dept D ON D.id_dept = A.in_dpt INNER JOIN sub_cat_ad S ON S.id_sub_cat = A.ads_in_Cat INNER JOIN cat_ad C ON C.idCat_ad = S.from_cat_ad ...

Optimizing a MySQL query (Update + subquery)

I want to change the values of column this in table_one where this = 1 and id value of that row exists anywhere in table_two's column other_id So I'm using this query: UPDATE table_one SET this='0' WHERE this='1' AND table_one.id IN (SELECT other_id FROM table_two); The query took several hours without yet finishing, so I was wonderi...

MySQL: Return 0 if row doen't exist

I've been bashing my head on this for a while, so now I'm here :) I'm a SQL beginner, so maybe this will be easy for you guys... I have this query: SELECT COUNT(*) AS counter, recur,subscribe_date FROM paypal_subscriptions WHERE recur='monthly' and subscribe_date > "2010-07-16" and subscribe_date < "2010-07-23" GROUP BY subscr...

MYSQL - Using conditional order bys

Hi, I'm having problems using conditional ORDER BYs. I want to do something like this SELECT promotion_expires,created_at FROM `notes` ORDER BY CASE WHEN (promotion_expires > NOW()) THEN 'promotion_expires DESC,created_at DESC' ELSE 'created_at DESC' END; ie. the result should first have rows where promotion_expires > NOW() o...

VB6 mySQL update problem

Hey all, i am having a weird problem with trying to update a record in my mySQL 5 database using VB6. This is my code when i log in: connDB Set rst = New ADODB.Recordset strSQL = "SELECT id, fName, lName, theCode, theDate, clockin FROM clockinout WHERE theCode = '" & theUsersUniqueID & "' AND theDate = '" & Format(Now, "YYYY/MM/DD") &...

MySQL: Help with script needed

CREATE TABLE `photos` ( `id` bigint(20) NOT NULL AUTO_INCREMENT, `photo` varchar(255) NOT NULL, `hotel_id` bigint(20) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=23061 DEFAULT CHARSET=utf8 So, i have table 'photos.' Now i want ALTER this table and add column 'type'. ALTER TABLE photos ADD COLUMN type varcha...

mysql select static list

I want to run an INSERT ... SELECT Manual query to insert 1 selected column column with the exact amount of 2 rows from one table to another. Along with this I would like to insert an additional column of static values. Example | selected column | static val | Variable 4 Variable 9 sta...

mysql query in OO Base have to avoid some compares

Hello. I'm totally blank about sql, but im have to make sql query in OO Base. Query have to avoid compare, when cell in table "Search" is blank. My code dont work. I hope somebody will help me. SELECT "D"."Name", "D"."SName", "D"."Date of", "D"."Type", "D"."Place", "D"."Unit1", "D"."Unit2" FROM "Data" AS "D", "Search" AS "S" ...

MySQL, Check if a column exists in a table with SQL

I am trying to write a query that will check if a specific table in MySQL has a specific column, and if not — create it. Otherwise do nothing. This is really an easy procedure in any enterprise-class database, yet MySQL seems to be an exception. I thought somethig like IF EXISTS (SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHE...

Altering Mysql Table column to be case sensitive

I have a table in my Mysql database, which is used for authentication. And now, I need to make the authentication case sensitive. Googling around, I have realized Mysql columns are case insensitive (contrary to Oracle) for search operations and the default behavior can be changed while creating the table by specifying the "binary" ie. ...

Returning random rows from mysql database without using rand()

I would like to be able to pull back 15 or so records from a database. I've seen that using WHERE id = rand() can cause performance issues as my database gets larger. All solutions I've seen are geared towards selecting a single random record. I would like to get multiples. Does anyone know of an efficient way to do this for large datab...