OT: MySQL GROUP_CONCAT Question

Are there any MySQL gurus here who understand MySQL's
GROUP_CONCAT
function? I'm trying to figure out how it works.
This is the query I started with:
$res = mysql_query ("SELECT * FROM cia_ppl CP
LEFT JOIN gw_geog GG on GG.IDArea = CP.ID_Name
LEFT JOIN cia_notes CN on CN.IDName = CP.ID_Name
WHERE CP.Pop != 0") or die (mysql_error());
It works, except that it only displays the first value in
cia_notes.ID_Note in a particular cell. For example, consider
the
following example where there are two notes listed for the
U.S. in table
cia_notes...
ID_Name \ ID_Note
can \ Pop
mex \ Ppl
usa \ Pop
usa \ Ppl
My web page might display the following:
Name \ Population \ Notes
Canada \ 60 million \ Pop
Mexico \ 80 million \ Ppl
United States \ 300 million \ Pop
When I want the last row to look like this:
United States \ 300 million \ PopPpl
I want to use MySQL's SEPARATOR function to insert commas and
a PHP
str_replace to convert it to superscripts, like this:
United States \ 300 million \ 1,2
At any rate, below is the script I came up with to tap into
the
GROUP_CONCAT function. All the data in my table displays
correctly,
except that it now displays no notes (ID_Note) at all. Thanks
for any tips.
SELECT CP.ID
, CP.ID_Name
, CP.Pop
, CP.Pop2
, CP.AgeMed
, CP.Age0
, CP.Age15
, CP.Age65
, CP.Sex
, CP.LifeExp
, CP.PopGrowth
, CP.LitTotal
, GG.IDArea, GG.Name
, DT.ppl_notes
FROM cia_ppl CP
LEFT JOIN gw_geog GG ON GG.IDArea = CP.ID_Name
LEFT OUTER JOIN (
select ID_Name
, GROUP_CONCAT(ID_Note) as ppl_notes
from cia_notes
where Cat = "Ppl"
group
by ID_Name
) as DT
ON DT.ID_Name = CP.ID_Name
WHERE CP.Pop != 0
and CP.ID_Name != 'ear'
AND CP.ID_Name != 'eru'
GROUP BY GG.Name
ORDER BY CP.ID
www.geobop.org - Family Websites
www.invisible-republic.org - Adult political websites (Mature
adults only)

this prod_id to the prim key.
-----------^^
"Field 'prodid' doesn't have a default value"
-------------^
Typo?
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.projectseven.com/go
- DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs,
Tutorials & Resources
==================
"Deon H" <[email protected]> wrote in message
news:[email protected]..
> Hi there. (I know this is propably not the right forum
to ask here, but
> the other forums don't help a lot. Please help me.)
>
>
>
> I have been using phpMyAdmin for a couple of years now
and simply love
> it.
> I have just created a new DB with 6 fields of which the
1st one is
> named: prod_id.
> type: smallint
>
> The rest of the fields are the default settings as
usual. I have changed
> this prod_id to the prim key.
>
> For some reason which I cannot figure out why, does not
show under
> "extra" as "auto_increment".
>
> I have double chacked the other db's I have created
exactly as I have
> done this one, and there is says "auto_increment".
> When I now try to add a record to the DB, I get this
error: "Field
> 'prodid' doesn't have a default value"
>
> Please advise where I am doing something wrong.
>
> Sincere regards,
> Deon

Similar Messages

  • MySQL /JDBC Question

    I began playing with JDBC a few days ago. I set up a database using mySQL and wrote a simple java program that will connect to it. Works good from the computer that holds the database.
    I try and run the same program from my secondary computer which does not have mySQL or ODBC mySQL drivers, I get com.mysql.jdbc.Driver for an error message. (Trying to access the database on my main computer via ip/databasename)
    My Question is, do you HAVE to have mySQL or Connector/ODBC installed on a computer if you wish to connect to a database on other computer??
    Here's where it prints the error message...
    try
    Class.forName("com.mysql.jdbc.Driver");
    catch (Exception e)
    JOptionPane.showMessageDialog(null, "ERROR = " + e.getMessage());
    I use this as my url..
    private final String url = "jdbc:mysql://122.122.122.122:3306/test123";
         

    Say I want to make a simple web applet that will
    access a database on my computer. The only way my
    vistors to my website will be able to access the
    database via the web applet is by having mySQL JDBC
    driver installed on their computers?yes.
    however.
    you can package up the JDBC driver as part of your jar with your applet so it doesn't require the user to "install" anything. it's just part of your applet.

  • Quick MySQL Indexing question

    Hi all,
    I know this is not strcitly a JDBC problem, but i was wodering if you have any ideas anyhow...
    I've implemented an Index on two of my columns in a table in my MySQL db. My question is, when i insert new rows into the database, is the index automatically updated? If not, how do I go about updating the Index?
    Many thanks,
    BBB

    I thought the database would manage that for you. AFAIK, you don't have to do anything. That's the way it is in Oracle. I thought that was true for all RDBMS. - MOD

  • Mysql database question

    Let's say that I am making a java program that connects to a Mysql database and uses the database "MyDatabase".
    Forgive me, but I am relating this to a Microsoft Access database.
    The database is not on a network, but is (or will be installed) on the user's machine. In otherwords, the database will be on the user's machine and the changes to the database will only affect that user.
    If I am to let a user use this program, will they have to also have Mysql installed for the program to access the database and pull information from it?
    --Thanks!                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                

    Let's say that I am making a java program that
    connects to a Mysql database and uses the database
    "MyDatabase".[snip]
    The database is not on a network, but is (or will be
    installed) on the user's machine.[snip]
    If I am to let a user use this program, will theyhave
    to also have Mysql installed for the program toaccess
    the database and pull information from it?Yes.
    (if you are asking if the code could directly
    access/manipulate MySQL datafiles without going
    through the MySQL program, I suppose in theory you
    could, but I seriously doubt you really want to)The reason being is that it would be a client database for their own use, as oppose to sharing the database with others.
    In any case, Thanks!
    Next question: is there any place where I could go to find code that would treat the Mysql database as a client database (so far, the code that I found requires Mysql to be installed and running in the background on the user's machine)?

  • Mysql charset question

    well I just got Mysql Browser query and I was modifying some of the variables inside the table from varchar to longtext and it ask me for the charset. So my question is: Which one should I use ? The application its used on a spanish enviroment.
    Thanks!

    Uhh, one of the sets that contains spanish characters, I suppose...
    http://dev.mysql.com/doc/mysql/en/charset-charsets.html
    looks like your choices are some universal charsets (utf8 and ucs2) and some "western" sets. You probably ought to pick a charset that also has a spanish collation (if you want to do native-language sorting).

  • MySQL query question

    Hi All,
    I've got 2 MySQL tables, movie and movie_tag. The movie table contains a movie_id column and the movie_tag table contains 2 columns, movie_id and tag_id. I know how to correctly join them, what I would like to know is if I have this query:
    SELECT * FROM movie LEFT JOIN movie_tag USING movie_id
    and save it as a result set in a language like PHP or Python can I:
    1. Loop through and only display each movie_id once, BUT...
    2. Also display all the tag_id's without nested-looping.
    I.e. I would like to list then something like:
    -- movie_id_1
    |-- tag_id_1
    |-- tag_id_2
    -- movie_id_2
    |-- tag_id_1
    Thanks for any help you can give!

    Your query will give you the cartesian product of movie and movie_tag, which means (given your example list) the output rows will look like this:
    movie_id_1 | tag_id_1
    movie_id_1 | tag_id_2
    movie_id_2 | tag_id_1
    You can then create the list you've shown above by post-processing in your procedural language of choice: loop over the results, track when movie_id changes, indent accordingly.

  • Coldfusion fetch mysql query question

    Hi:
    Here is my coldfusion code:
    <cfquery name = "query" datasource = "cfmysql" result = "result">
         SELECT COUNT(*) FROM students WHERE gender = 'boy'
    </cfquery>
    And then I want to check if value is greater than 0. I then do:
    <cfif existSearchHintsQuery.COUNT(*) gt 0>
    But coldfusion gives me an error at the * character, the colume of the mysql result is "COUNT(*)", so I really need the * character.
    How do I fetch that count number?
    Thanks.

    You need to use an alias so you can access the COUNT(*) like any other column:
    <cfquery name="yourQueryName" datasource="cfmysql" result="result">
        SELECT COUNT(*) AS TotalStudents FROM students WHERE gender = 'boy'
    </cfquery>
    <cfif yourQueryName.totalStudents GT 0>
    ... do something ...
    </cfif>
    Also, read up on using cfqueryparam  (if you are not using it already)
            http://livedocs.adobe.com/coldfusion/8/Tags_p-q_18.html

  • MySQL Version Question

    Up till now I have been on a server using version 4.1 but I
    have now
    purchased my own little bit of the internet and I have the
    option of
    installing version 5, are there any major advantages to me in
    doing this in
    relation to the shopping cart software I am using i.e. WA
    eCart and
    Cartweaver ? or are the new features not relevant to these
    types of
    applications until I start rolling my own so to speak.
    Thanks
    Dave Buchholz
    I-CRE8
    www.i-cre8.co.uk
    Skype ID: I-CRE8

    Thanks David
    as ever concise and constructive advice
    Dave Buchholz
    I-CRE8
    www.i-cre8.co.uk
    Skype ID: I-CRE8
    "David Powers" <[email protected]> wrote in message
    news:eeu26s$ft$[email protected]..
    Dave Buchholz wrote:
    > Up till now I have been on a server using version 4.1
    but I have now
    > purchased my own little bit of the internet and I have
    the option of
    > installing version 5, are there any major advantages to
    me in doing this
    > in
    > relation to the shopping cart software I am using i.e.
    WA eCart and
    > Cartweaver ? or are the new features not relevant to
    these types of
    > applications until I start rolling my own so to speak.
    If you have the option of version 5, take it. It will make
    upgrading to
    subsequent versions a lot easier. MySQL 5 offers improved
    features such
    as stored procedures and views. Although they're not
    supported by
    Dreamweaver, you may find them useful, particularly once you
    decide to
    start developing things on your own.
    AFAIK, MySQL 5.2 is likely to be the important upgrade
    (probably at
    least a year away), as it's planned to introduce support for
    foreign key
    restraints in the default MyISAM table. At the moment, only
    InnoDB
    tables have support for foreign key restraints, but most
    hosting
    companies don't provide support for InnoDB.
    David Powers
    Adobe Community Expert
    Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
    http://foundationphp.com/

  • MySQL Date Question

    I have two DATETIME columns in a table. Is it possible to get the difference between the two dates and then format the output as H:M P?
    I've been trying to get this to work for a while... but now I'm not even sure it's possible.

    I have two DATETIME columns in a table. Is it possible
    to get the difference between the two dates and then
    format the output as H:M P?A MySql-query along these lines might just do the job:
    SELECT SEC_TO_TIME(UNIX_TIMESTAMP(yourDATETIME_1) - UNIX_TIMESTAMP(yourDATETIME2)) AS TimeDifference FROM yourTable;
    It gives you the time difference (conveniently availaible as TimeDifference) in a HH:MM:SS format. Additionally, you can use the TIME_FORMAT() function to convert it to a more suitable format, e.g.
    SELECT TIME_FORMAT(SEC_TO_TIME(UNIX_TIMESTAMP(yourDATETIME_1) - UNIX_TIMESTAMP(yourDATETIME2)), "%H:%i") AS TimeDifference FROM yourTable;
    - giving you the hours and minutes. For details, see http://www.mysql.com/doc/en/Date_and_time_functions.html
    Maybe all of this isn't exactly what you were looking for, but at least it should give you an idea of the possibilities and something to work from. Hopefully!
    nr

  • MySQL upgrade question

    Not sure if this is the appropriate forum for a mySQL upgrade--but since Oracle owns mySQL now I thought I would give it a try.
    I just ran the mysql_upgrade and can't locate the log to review. Anyone know where the log is dumped?

    Hi
    Please post your issuen on forums.mysql.com/
    Regard
    Helios

  • Mysql java question?

    Hello,
    I am writing a java program to connect with mysql, the database two tables: order and items.
    In the order the orderNo is a unique value, and appears again the items table for each book ordered.
    Could any advise, if I wanted to delete the orderNo from the order table, and also delete all the records in the items table with the same orderNo, could I achieve this in one sql statement?
    Thanks
    table (order):
    orderNo
    table (items):
    orderNo
    bookname
    quantity
    price

    example for orderNo 2:
    DELETE items,order FROM items,order WHERE order.orderNo=2 and items.orderNo=2Haven't tried this myself, though.
    regards

  • MySQL - Alias Question

    Hi Chaps, 
    Have a quick one for you...
    In a SQL Query, I know you can create an alias for column name, eg.
    ...tbl_jobxml.job1 as job2
    but can you create an alias for the value within that column, eg.
    ...tbl_jobxml.job1='y' as job2='Complete'
    Sorry if this is dumb question, but better to ask that claim ignorance!

    Hi Guys,
    sorry to the delay in responding, basically this is what I want to do:
    I want to show all results when:
    - tableA
    projectstatus='complete'
    - tableB
    projectstatus='complete'
    - tableC
    jobstatus='y'
    I'm familiar with UNIONs and INNER JOINs, it's just not sure how to go about getting all the results form the 3 tables, when the values are different.

  • MySQL SQL Question

    OK fellas. Gentle on the newbie.
    I have my datasource set up, I have the MySQL Query Browser
    working and I'm poking around a bit with the World dB tables.
    I can't seem to get why this:
    SELECT * FROM countrylanguage c; ORDER BY IsOfficial;
    isn't doing a thing. No error, but it surely doesn't seem to
    be alphabetizing on IsOfficial.
    Thanks!
    Rick

    Try adding ASC or DESC to the end of it.
    Brendon
    "webspinner" <[email protected]> wrote in
    message
    news:eo6akr$2r7$[email protected]..
    > OK fellas. Gentle on the newbie.
    >
    > I have my datasource set up, I have the MySQL Query
    Browser working and
    > I'm
    > poking around a bit with the World dB tables.
    >
    > I can't seem to get why this:
    > SELECT * FROM countrylanguage c; ORDER BY IsOfficial;
    >
    > isn't doing a thing. No error, but it surely doesn't
    seem to be
    > alphabetizing
    > on IsOfficial.
    >
    > Thanks!
    >
    > Rick
    >

  • MySQL - Another 'Can't connect through mysql.sock' question...

    Hey, folks.
    So I'm trying to install MySQL to run with PHP on my PowerBook G4 (running 10.4.7, non-server edition) to use it to test out a shopping cart program for a website I'm building.
    I had it working as of Monday, when I installed it, got all the permissions set, built the necessary tables, and changed the root password (and logged in just to make sure it worked before retiring for the night)...but today I realized that I had somehow installed the wrong version of MySQL (I connected to it earlier today and discovered it was 4.026 - and I needed to be running MySQL 4.1.20, in order to be running the same version as my webhost).
    So I decided to upgrade. I downloaded and installed the 4.1.20 file, followed the directions about creating the system tables, changed permissions via sudo chown -R mysql:mysql data...and now, when I go to change the root user password (just to make sure it's still the same as it was), I get the following error:
    error: 'Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)'
    Check that mysqld is running and that the socket: '/tmp/mysql.sock' exists!
    This error also occurs when I try to simply startup MySQL. I also now find I can't connect via MySQL Admin, either - it gives me the same error. Pinging the host works, however.
    Sooo...anyone have any ideas? I've read up on the forums re: Apple changing the socket to /var/mysql/mysql.sock as of 10.4.4, but it seems that would have affected me earlier this week when I was running the previous version of MySQL, too (I certainly haven't upgraded the OS since then).
    Regardless, I can't connect through MySQL Admin using the /var/mysql/mysql.sock socket, anyway...nor the standard /tmp/mysql.sock.
    Any thoughts on what might be causing this? I should confess, I'm well-versed in DOS (ugh), but UNIX is not really my strong suit, so I'm still figuring out how to get around in the Terminal...
    Thanks so much for any input you can give me!
    (Oh, one more thing, since it'll probably come up - I'm not currently connecting via PHP, but I will be eventually. Right now, I just want to be able to change my root password, and login from the Terminal)!
    Thanks again!\
    PowerBook G4 1GHz 15   Mac OS X (10.4.7)  

    Alright, folks.
    Somehow my computer has fixed itself. After wiping the mysql directories entirely, then reinstalling, I was still getting the same error.
    After going back to the original "MySQL-On-Mac" site at Marc Liyanage's entropy.ch site & following some of the instructions there, somehow my problem seems to have fixed itself.
    I wish I could tell you what the solution was (to benefit anyone else having this problem), but since I was simply following the unix commands listed there (without much explanation, at times, as to what they were doing), I just know that somehow it worked.
    (But if I had to make a guess, I think it had to do with starting the server via sudo ./bin/mysqld_safe &)...

  • PHP & MySQL recordset question

    Hello all,
    I've been searching for a while, and I can't seem to find an
    answer, so sorry if this has been asked a lot.
    I've got 5 tables that have similar information (id,
    firstname, lastname, topic, thread, and date).
    What I'm trying to do is have one search box where the user
    types in a keyword. Then it searches all 5 tables in both the topic
    and thread collumns. Then it displays the results from all 5 tables
    and orders them by date.
    I'm using dreamweaver 8, PHP, and MySQL.
    I've tried to use this format:
    SELECT column1 column 2
    FROM table1
    WHERE thread OR topic LIKE %variable%
    UNION
    SELECT column 1 column2
    FROM table 2
    WHERE thread OR topic LIKE %variable%
    ORDER by date DESC
    but keep getting error messages.
    Is this possible? If so, can anyone help me figure out how to
    do this, or where I can find a good tutorial?
    Thanks.

    Thanks for your reply.
    Sorry, here is the entire SQL statement:
    SELECT eventforum.FirstName, eventforum.LastName,
    eventforum.topic, eventforum.Thread, eventforum.`Date`
    FROM eventforum
    WHERE Thread or topic LIKE %colname%
    UNION
    SELECT fundforum.FirstName, fundforum.LastName,
    fundforum.topic, fundforum.Thread, fundforum.`Date`
    FROM fundforum
    WHERE Thread OR topic LIKE %colname%
    UNION
    SELECT generalforum.FirstName, generalforum.LastName,
    generalforum.topic, generalforum.Thread, generalforum.`Date`
    FROM generalforum
    WHERE Thread OR topic LIKE %colname%
    UNION
    SELECT persupport.FirstName, persupport.LastName,
    persupport.topic, persupport.Thread, persupport.`Date`
    FROM persupport
    WHERE Thread OR topic LIKE %colname%
    UNION
    SELECT prosupport.FirstName, prosupport.LastName,
    prosupport.topic, prosupport.Thread, prosupport.`Date`
    FROM prosupport
    WHERE Thread OR topic LIKE %colname%
    UNION
    SELECT soldier.FirstName, soldier.LastName, soldier.topic,
    soldier.Thread, soldier.`Date`
    FROM soldier
    WHERE Thread OR topic LIKE %colname%
    ORDER BY 'Date' DESC
    the variable colname is defined as:
    Name: colname
    Type: Text
    Default Value: -1
    Runtime value: $_POST['searchbox']
    here is the error message that I get with this setup:
    Missing type for variable:colname
    If I remove the variable and the WHERE statements, I get this
    error message:
    MySQL Error #: 1271
    Illegal mix of collations for operation 'UNION'
    If I remove the variable, the WHERE staements, and the ORDER
    BY statement, I get the following error message:
    MySQL Error #: 1271
    Illegal mix of collations for operation 'UNION'

Maybe you are looking for