Results 1 to 9 of 9

Thread: [RESOLVED] joining with information_schema table

  1. #1

    Thread Starter
    Still learning kebo's Avatar
    Join Date
    Apr 2004
    Location
    Gardnerville,nv
    Posts
    3,762

    Resolved [RESOLVED] joining with information_schema table

    what is going on?

    something funny is going on I keep trying to post and end up with a new error page I've never seen, then I end up with a browser nested inside the window used to write the post.

    I'm not simply being a wise guy here. I really have a question I need help with

    Name:  Capture.jpg
Views: 433
Size:  14.1 KB
    Name:  Capture1.jpg
Views: 465
Size:  26.9 KB
    Last edited by kebo; Aug 6th, 2016 at 09:59 AM.
    Process control doesn't give you good quality, it gives you consistent quality.
    Good quality comes from consistently doing the right things.

    Vague general questions have vague general answers.
    A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.

    ______________________________
    Last edited by kebo : Now. Reason: superfluous typo's

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: joining with information_schema table

    There is currently an odd issue with the forums... there are some things (and combinations of things) that cause that error message. One is the word System 32 (without a space), and others are so confusing we haven't worked out what is happening (eg: posting any 2 of 3 lines of a particular piece of code works, but all 3 together fails). The admins are looking into it, but we don't know when it will be fixed.

    Try posting part of what you want, and edit in the other bits until it fails (you are likely to see a spinner not finishing at that point)... feel free to attach your question in a text file to save some effort.

  3. #3

    Thread Starter
    Still learning kebo's Avatar
    Join Date
    Apr 2004
    Location
    Gardnerville,nv
    Posts
    3,762

    Re: joining with information_schema table

    Ok, thanks
    Here is the post as an attachment.
    Attached Files Attached Files
    Process control doesn't give you good quality, it gives you consistent quality.
    Good quality comes from consistently doing the right things.

    Vague general questions have vague general answers.
    A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.

    ______________________________
    Last edited by kebo : Now. Reason: superfluous typo's

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: joining with information_schema table

    Testing to see if I can post the contents of your attachment...
    Hey all,
    I am trying to give my user a way to use "Nice Names" for one of my tables, and I need help with my select statement. I'm running mySQL a server instance.

    I have 2 tables.

    Table 1 has columns c1, c2, c3,..., cn and I have another table that looks like this...

    fieldName | niceName
    'c1' | 'column 1'
    'c2' | 'column 2'
    'c3' | 'column 3'
    'c4' | 'column 4'

    where the fieldName value is a column name from table1

    I am able to select all of the columns from table 1 using this...

    Code:
    SELECT COLUMN_NAME
    FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA='myDB' AND TABLE_NAME='table1'
    but I don't know how to write the join to include any of the 'niceNames' that may exist in table2. I have tried the following (as well as other variations upon the theme), but I seem to be floundering from my lack of experience with joins.

    Code:
    SELECT COLUMN_NAME
    FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA='myDB' AND TABLE_NAME='table1'
    INNER JOIN `common_field_names_table`
    ON `INFORMATION_SCHEMA`.`COLUMN_NAME` = `table2`.fieldName
    Any help would be greatly appreciated.
    thanks
    kevin
    edit: it worked, I guess the Quote tags etc helped.

  5. #5

    Thread Starter
    Still learning kebo's Avatar
    Join Date
    Apr 2004
    Location
    Gardnerville,nv
    Posts
    3,762

    Re: joining with information_schema table

    yea, that's the post. I didn't try wrapping it in a quote.
    Process control doesn't give you good quality, it gives you consistent quality.
    Good quality comes from consistently doing the right things.

    Vague general questions have vague general answers.
    A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.

    ______________________________
    Last edited by kebo : Now. Reason: superfluous typo's

  6. #6
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: joining with information_schema table

    Move the WHERE clause to after the Joins (which are actually part of the From clause), and I suspect you want a Left join (as you implied the other table may not have matching rows)
    Code:
    SELECT COLUMN_NAME, `table2`.fieldName
    FROM INFORMATION_SCHEMA.COLUMNS 
    LEFT JOIN `common_field_names_table`
    WHERE TABLE_SCHEMA='myDB' AND TABLE_NAME='table1'
    ON `INFORMATION_SCHEMA`.`COLUMN_NAME` = `table2`.fieldName

  7. #7

    Thread Starter
    Still learning kebo's Avatar
    Join Date
    Apr 2004
    Location
    Gardnerville,nv
    Posts
    3,762

    Re: joining with information_schema table

    I wish I understood sql a little better, because then I could probably figure this out. This is the SQL I am using, but there is still an issue with it.
    Code:
    SELECT `COLUMN_NAME`, `common_field_names_table`.`fieldName`
    FROM `INFORMATION_SCHEMA`.`COLUMNS`
    LEFT JOIN `common_field_names_table`
    WHERE `TABLE_SCHEMA`='myDB' AND `TABLE_NAME`='common_field_names_table'
    ON `INFORMATION_SCHEMA`.`COLUMN_NAME` = `common_field_names_table`.`fieldName`
    When I run it, I get the (always not very helpful) message back from the server....
    SQL Error (1064): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE `TABLE_SCHEMA`='myDB' AND `TABLE_NAME`='common_field_names_table' ON `IN' at line 4
    Can you see why the server doesn't like the syntax?
    Process control doesn't give you good quality, it gives you consistent quality.
    Good quality comes from consistently doing the right things.

    Vague general questions have vague general answers.
    A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.

    ______________________________
    Last edited by kebo : Now. Reason: superfluous typo's

  8. #8

    Thread Starter
    Still learning kebo's Avatar
    Join Date
    Apr 2004
    Location
    Gardnerville,nv
    Posts
    3,762

    Re: joining with information_schema table

    ok, after splashing around in the water, I finally have it...

    Code:
    SELECT c.COLUMN_NAME , t2.`niceName` 
    FROM `INFORMATION_SCHEMA`.`COLUMNS` As c
    LEFT JOIN `table2` as t2
    ON c.COLUMN_NAME  = t2.fieldName
    WHERE c.`TABLE_SCHEMA`='mydb' AND c.`TABLE_NAME`='table1'
    Every time I have to do this stuff, it make so much sense after the fact. Problem is I don't do it enough to make it stick and I have to figure out again each time.
    Thanks si
    Process control doesn't give you good quality, it gives you consistent quality.
    Good quality comes from consistently doing the right things.

    Vague general questions have vague general answers.
    A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.

    ______________________________
    Last edited by kebo : Now. Reason: superfluous typo's

  9. #9
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: [RESOLVED] joining with information_schema table

    No worries, but I am disappointed in myself for not moving the ON line along with the rest of the Join

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width