mysql

MySQL: Updating a left-joined view, where right table has no matching data.

I'm curious to know if this is actually possible... In this simplified example, I have: Table_A: Table_B: +------+--------+ +------+--------+ | id | data_1 | | id | data_2 | +------+--------+ +------+--------+ | 1 | Hello | | 1 | There | +------+--------+ +------+--------+ | 2 | Hi | +------+--------+...

Using php to return GROUP_CONCAT('column x') values

I am trying to use PHP to return SQL values into an HTML table. I am able to get every column to populate without a problem except for the last column, "GROUP _ CONCAT (provision_id)." Relevant code: <?php global $wpdb; $wpdb->show_errors(); $contents = $wpdb->get_results( $wpdb->prepare("SELECT salaries.id, name, remaining, contract...

MySQL joins to display categories, subcategories and subsubcategories

I have three tables: categories, subcategories and subsubcategories. I want to display a list that's formatted like: dvds cds cds > pop cds > blues cds > new age cds > new age > whale noises books books > cowboys books > zombies I've managed to display everything except for the names of categories on their own when they have children,...

PHP VLookup (conditional match) Alternative?

How do I return the results for the provision_id column so that they are conditional on contracts.id for each row? Right now, I get the same result on every row. The desired effect is sort of like VLookup in Excel. Not sure how to use if else/sql values to achieve it in PHP though. Relevant code: <?php global $wpdb; $contents = $wpdb-...

Finding the higest voted Question in last week. (sql query)

Hello I have a 3 sql tables: qotwQuestion1a(QuestionId [primarykey], Question, MemberId, PostDate); qotwVote1a (QuestionId [primarykey], MemberId [primarykey], Vote1a); qotwMember (MemberId [primarykey], Name, Password, emailId); I want to write a sql query to find the QuetionId and MemberId of the Question that has the highest vote...

Doing an INSERT INTO tableA with sub-SELECT on tableB sorted with ON DUPLICATE KEY UPDATE

I have a table, tableA that I want to resort and then insert / update each resulting row into tableB. Currently I have something like this: delete from tableB; set @place = 0; INSERT INTO tableB (id, place, name, colD, colF) SELECT (id, greatest(@place := @place + 1, 0) from tableA order by colD desc; This works, but I don't want to d...

Oracle Data Dump and Data Restore

What's the "standard" (defacto or otherwise) way to dump an Oracle database/instance to an ascii or binary file, and then reimport that file into a separate Oracle instance. I'm looking for the equivalent of mysqldump, but for the Oracle platform. ...

Data Modeling - how to handle two, dependent "status" columns?

I've run across something that's bugging me just enough that I wanted to come here and seek out a sort of "best practice" type of advice from you guys (et gals) I have a table in my model, let's call it prospect. Two separate external systems can provide an update for rows in this table, but only as a "status" of that record in those r...

What is PDO scrollable cursor?

What is "Fetching rows with a scrollable cursor" all about? ...

Problems ordering the results of a SQL query when I have ties

My tables look like this: qotwQuestion1a QuestionId [primarykey] Question MemberId PostDate qotwVote1a QuestionId [primarykey] MemberId [primarykey] Vote1a qotwMember MemberId [primarykey] Name Password emailId The Sql query below sums the number of votes for each questionId (which has a...

calculating a top 5 in php and mysql

Hey I've made a rating system in php and mysql and now I want to select a top 5, I've made something but if a user adds a rating (with the max) it's nr 1 ranking. How do you guys do it in php and mysql ? the table looks like this: -- id -- mid -- uid -- rating The rating is a number from 1 to 5 Thanks in advance! ...

Creating unique usernames

So I have a system that is going to allow specific users the ability to create new user accounts but, for several reasons, they cannot get a listing of all users on the system. That could make creating new user names difficult (if they can't see a list of used names) Are there any standard ways of creating a user name out of a person's...

MySQL regular expression operations

The set-up A mysql table called "mytable" has a VARCHAR field "data". The field contains a string in the format of: name1'value1''name2'value2'' ... nameN''valueN I'm aware this data is denormalized -- I've been forced to use ' as the delimited since this is the only character that is not allowed as a name or value. Here are some ...

PHP MySQL in 1 class & 1 file

Hi, I'm looking for a many-in-one PHP MySQL 1 class/file with the features: Connect to DB server Select database CRUD Prepare & binding Thank you in advance! ...

Meaning of 3 byte numeric in mysql (MEDIUMINT)

Funny thing I've found abount mysql. MySQL has a 3 byte numeric type - MEDIUMINT. Its range is from -8388608 to 8388607. It seems strange to me. Size of numeric types choosen for better performance, I thought data should be aligned to a machine word or double word. And if we need some restriction rules for numeric ranges, it must be exte...

Keeping some choices in the Table for the Field of Type Dropdown

Hi, i am having a Table named Attributes which has id form_id label size sequence_no Type 1 1 Name 200 1 Text 2 1 Age 150 2 Number 3 1 Address 300 3 Textarea 4 1 Gender 200 4 Dropdown I am having the doubt how can i keep the Choi...

Cursor-fetched variable in prepared statement within a stored procedure?

Hullo, Can any help me shed some light on what's going on when I try to prepare a statement from a string that contains a cursor-fetched variable? Below is the procedure that I'm trying to create. When I create it without the prepared statement, and replace those three lines with SELECT @export_sql_stmt, the output verifies that the S...

MySQL: Insert one row for each key in foreign table for each distinct value in table

table1: col1 | col2 ------------- 0 value1 1 value1 2 value1 0 value2 1 value2 2 value3 primary key is col1 and col2 together table2: col1 | col3 ------------- 0 name1 1 name2 2 name3 primary key is col1. col1 in table1 is referring to col1 in table2. I need a mysql query that goe...

SQL help: COUNT aggregate, list of entries and its comment count

So, what I intended to do is to fetch a list of entries/posts with their category and user details, AND each of its total published comments. (entries, categories, users, and comments are separate tables) This query below fetches the records fine, but it seems to skip those entries with no comments. As far as I can see, the JOINs are go...

Calling the stored procedure

CALL rebuild; How would i call this each and every time dynamically without doing a query in database. I mean each time i update some value, i need to call this to make sure the changes are in effect. ...