Sql Problems, Same Field Names In Multiple Mysql Tables?

I have a keyword search that searches multiple DB tables for thumbnail images using UNION ALL. I have two pages, results.php, and view.php.  My goal is to able to click a thumbnail image on results.php and be directed to a larger version of that same image on view.php. The problem is each image in all my tables uses the field name "id" so when I click a thumbnail on results.php I get two different images with the same id from different tables.  I tried changing the id's to different names, but when it was time to pass url parameters I can only choose 1 value. (if you can choose more than 1 I don't know how).  So my question is why are my id's from different tables being grouped together, and how can I change this?
Image Results Page (which works perfect):
SELECT *
FROM table1
WHERE keyword LIKE %colname% OR id  LIKE %colname% 
UNION ALL
SELECT *
FROM table2
WHERE keyword LIKE %colname% OR id  LIKE %colname% 
View Image Page (having problems here):
SELECT *
FROM table1
WHERE id = colname
UNION ALL
FROM table2
WHERE id = colname

Yes, that is going to be a problem - and it's just the beginning of your problems when you do not normalize your data. Your data model is not correct. You should not be storing similar data in 15 tables - it's a really big mistake.
To solve your current problem you would need to include a table identifier in the query results in the Image results page, and pass that to the view page and then use PHP to dynamically create the SQL with the correct table....ugh!

Similar Messages

  • Finding same column name from multiple database tables

    I am needing to find all tables in a database that contain the same column. ie: which tables in database A have col_a in it.
    Is it possible to do a sql code to qry all of this?
    Thanks

    No, Ignacio did not, at least, not really. ;)
    The usage of ALL_TAB_COLUMNS only has info for tables which the actual user has access to.
    If you need to be sure that you search each and every table, you have to use DBA_TAB_COLUMNS (or the connected user must be a super hero...).
    Just wanted to point that out.
    Regards,
    Guido

  • How to get the field name of an internal table during runtime?

    How to get the field name of an internal table during runtime?

    Hi  Sudhir,
    Declare and Use Get Cursor Field in Your Prm to get the field Name of the Intenal Table
    Example Code:
        <b>  DATA: v_field(60).                        " Insert this code.
         GET CURSOR FIELD v_field.        " Insert this code.</b>
         <b>CHECK v_field = 'ITAB-KUNNR'.    " Insert this code. (or)
    Write: v_field.</b>
    Regards,
    Ramganesan K.

  • Reg: field names of an Internal table

    Hi all,
    I'd like to display all the field names of the internal table or a structure.
    I want it very urgent.
    Use ful answers will be awarded greatly.
    Thanks in advance.
    Jagan Mohan.

    Hi Jagan,
      Use the below code.
    TYPE-POOLS: SYDES.
    DATA: TD TYPE SYDES_DESC.
    DATA: BEGIN OF WA OCCURS 0,
           CONTINUE     TYPE C,
           NAME(15)     TYPE C,
          END OF WA.
    TYPES:BEGIN OF STR1,
            NUM(3) TYPE N,
            NAME(20) TYPE C,
          END OF STR1.
    *DATA: ITAB LIKE T247 OCCURS 0 WITH HEADER LINE.
    *DATA: ITAB TYPE STR1 OCCURS 0 WITH HEADER LINE.
    DATA: BEGIN OF ITAB OCCURS 0,
           NUM(3) TYPE N,
           NAME(20) TYPE C,
          END OF ITAB.
    DESCRIBE FIELD ITAB INTO TD.
    WA[] = TD-NAMES[].
    LOOP AT WA.
      IF WA-NAME = SY-REPID.
        DELETE WA.
        CONTINUE.
      ENDIF.
      SEARCH WA-NAME FOR '-'.
      IF SY-SUBRC = 0.
        DELETE WA.
        CONTINUE.
      ENDIF.
      SEARCH WA-NAME FOR '='.
      IF SY-SUBRC = 0.
        DELETE WA.
        CONTINUE.
      ENDIF.
    ENDLOOP.
    LOOP AT WA.
      WRITE: / WA-NAME.
    ENDLOOP.

  • Getting field names of an internal table

    Hi all,
    Does anyone know if exists a statement, function module or method that gets the field names of an internal table ?
    Thanks in advance,
    David

    Hi,
    See this
    REPORT typedescr_test.
    TYPES:
    BEGIN OF my_struct,
    comp_a type i,
    comp_b type f,
    END OF my_struct.
    DATA:
    my_data TYPE my_struct,
    descr_ref TYPE ref to cl_abap_structdescr.
    FIELD-SYMBOLS:
    <comp_wa> TYPE abap_compdescr.
    START-OF-SELECTION.
    descr_ref ?= cl_abap_typedescr=>describe_by_data( my_data ).
    WRITE: / 'Typename :', descr_ref->absolute_name.
    WRITE: / 'Kind :', descr_ref->type_kind.
    WRITE: / 'Length :', descr_ref->length.
    WRITE: / 'Decimals :', descr_ref->decimals.
    WRITE: / 'Struct Kind :', descr_ref->struct_kind.
    WRITE: / 'Components'.
    WRITE: / 'Name Kind Length Decimals'.
    LOOP AT descr_ref->components ASSIGNING <comp_wa>.
    WRITE: / <comp_wa>-name, <comp_wa>-type_kind,
    <comp_wa>-length, <comp_wa>-decimals.
    ENDLOOP.

  • CFUPDATE problem with field name beginning with a number

    I have a form (actually several) that is gathering data for a survey. I tried to use cfupdate to update the data elements and got a string index out of range error. I tested again without the form fields that began with numbers and it worked just fine. I then tried to enclose the offending field names in () and []. Both times I got same error. Does anyone have a work around for this? The code and error are below.
    Changing the field names is not really an option. This survey has almost 400 data points and most of the fields begin with the question number.
    Thanks
    DW
    <cfupdate datasource="#application.fdp_datasource#" tablename="arra_survey1" dbtype="ODBC" formfields = "entry_no, 2_a_fy09, '2_a_fy10', '2_a_fy11', '2_a_fy12', '2_b_fy09', '2_b_fy10', '2_b_fy11', '2_b_fy12', '2_c_fy09', '2_c_fy10', '2_c_fy11', '2_c_fy12', '2_d_fy09', '2_d_fy10', '2_d_fy11', '2_d_fy12', '2_e_fy09', '2_e_fy10', '2_e_fy11', '2_e_fy12', '2_f_fy09', '2_f_fy10', '2_f_fy11', '2_f_fy12', '2_g_fy09', '2_g_fy10', '2_g_fy11', '2_g_fy12', '2_h_fy09', '2_h_fy10', '2_h_fy11', '2_h_fy12', '2_i_fy09', '2_i_fy10', '2_i_fy11', '2_i_fy12', '2_j_fy09', '2_j_fy10', '2_j_fy11', '2_j_fy12', '2_k_fy09', '2_k_fy10', '2_k_fy11', '2_k_fy12', '2_l_fy09', '2_l_fy10', '2_l_fy11', '2_l_fy12', central_office, dept_office, incl_other, 3_a_fy09, 3_a_fy10, 3_a_fy11, 3_a_fy12, 3_b_fy09, 3_b_fy10, 3_b_fy11, 3_b_fy12, 3_c_fy09, 3_c_fy10, 3_c_fy11, 3_c_fy12, 3_d_fy09, 3_d_fy10 3_d_fy11, 3_d_fy12, 3_e_fy09, 3_e_fy10, 3_e_fy11, 3_e_fy12, 3_f_fy09, 3_f_fy10, 3_f_fy11, 3_f_fy12, 3_g_fy09, 3_g_fy10, 3_g_fy11, 3_g_fy12, 3_h_fy09, 3_h_fy10, 3_h_fy11, 3_h_fy12, 3_i_fy09, 3_i_fy10, 3_i_fy11, 3_i_fy12, 3_j_fy09, 3_j_fy10, 3_j_fy11, 3_j_fy12, 3_k_fy09, 3_k_fy10, 3_k_fy11, 3_k_fy12, 3_l_fy09, 3_l_fy10, 3_l_fy11, 3_l_fy12">
    String index out of range: -2
    The error occurred in C:\Inetpub\wwwroot\directory\process_arra_suvey_2.cfm: line 12
    12 : <cfupdate datasource="#application.fdp_datasource#" tablename="arra_survey1" dbtype="ODBC" formfields = "entry_no, 2_a_fy09, '2_a_fy10', '2_a_fy11', ...

    I think you have run one of CFUPDATE's limitations.  I am not 100% certain, but I do not think cfupdate provides a way to escape invalid column names like yours.  In which case you may need to do a regular UPDATE within a  cfquery instead... or rename your columns.
    fields that began with numbers
    Most databases discourage creating column names that start with a number (or other restricted characters).  While many databases will allow you to escape invalid names, it is simpler all around to avoid them altogether.  Otherwise, you may have to escape the names in every single query. The recommendations vary, but usually object names that begin with a  letter, and contain only letters, numbers and underscores are considered  safe.
    This survey has almost 400 data points and most of the fields begin with the question number.
    Four-hundred (400) is a lot of columns for a single table.  The fact that they all them seem to contain the same type of information (ie response to a question) is an indication that data should probably be stored in a separate table, as rows, not columns.  For example questions could be stored in one table, possible answers in another, and the results of an individual test/survey stored in a third table.  A structure like that is much easier to query, can easily accommodate changes (add/remove questions, responses, etcetera) without having modify the table every time.

  • How to find same field name from all tables?

    Dear All,
    I want to find those tables that contain a field name, say COMPANY_CODE, from all user tables. How can I do that by writing SQL?
    Many thanks,
    Andrew

    SELECT table_name
      FROM user_tab_columns
    WHERE column_name = 'COMPANY_CODE'Justin
    Distributed Database Consulting, Inc.
    http://www.ddbcinc.com/askDDBC

  • XML Parsing issue with same tag names at multiple levels.

    My XML has the same tag name , ID at different levels in the XML.
    <InventorySearch>
    <*ID*>ID1</*ID*>
    <interactionDate>2012-09-01T10:30:00Z</interactionDate>
    <DescribedBy>
    <value>Cycle Count extract</value>
    <Characteristic>
    <*ID*>ID2</*ID*>
    </Characteristic>
    </DescribedBy>
    <type>Cycle Count</type>
    <InventorySearchComprisedOf>
    <*ID*>ID3</*ID*>
    <quantity>
    <amount>1</amount>
    <units>EACH</units>
    </quantity>
    <itemDateComplete>2012-09-07T10:30:00Z</itemDateComplete>
    <itemStatus>Open</itemStatus>
    </InventorySearchComprisedOf>
    </InventorySearch>
    When I use the Extract function with XML Sequence, I am getting all the ID values concatenated.
    select extract(value(d),'//ID/text()').getstringval() as id1,
    extract(value(e),'//ID/text()'). getstringval() as id2
    from xxnbn_cc_response_xml_stg x,
    table(xmlsequence(extract(x.xml_column,'/InventorySearch'))) d,
    table(XMLSEQUENCE(extract(D.column_value,'//InventorySearchComprisedOf')))(+) E;
    Return values :
    ID1 - ID1ID2ID3
    ID2 - ID3
    Is this the right way to parse this type of XML?

    The answer would depend upon your version of Oracle
    select * from v$version
    and the desired result set you want to see.
    If you are 10.2 or later, than XMLTable would be easier to write, but I won't go that way until we know more about what you want to see.

  • Problem getting field names with OCI

    Hi,
    I am trying to retrieve the names of select fields through the
    OCI using OCIParamGet() followed by OCIAttrGet(). This seems to
    work OK, in most cases, except occasionally I get one field name
    concatenated to the following field name.
    Has anyone else seen this before, and if so, how do you get
    around it? Let me know if you need more details.
    Thanks in advance.
    Tim
    null

    That worked. Thanks!
    Peter Kls (guest) wrote:
    : Timothy Sim (guest) wrote:
    : : Hi,
    : : I am trying to retrieve the names of select fields through
    the
    : : OCI using OCIParamGet() followed by OCIAttrGet(). This seems
    to
    : : work OK, in most cases, except occasionally I get one field
    : name
    : : concatenated to the following field name.
    : Try evaluating the string length returned by the OCIAttrGet
    call.
    : The name string is not (always) \nul terminated.
    : : Thanks in advance.
    : : Tim
    : good luck
    : Peter
    null

  • Searching multiple mysql tables, Joins?

    I'm creating a mysql keyword search on my website and I know how to search a single mysql table, my problem is I need to search 15 different tables simultaneously, they also all have the same column names. I was told I have to you JOINS but i've never used them before. How is this done?
    MY SQL SELECT:
    SELECT *
    FROM mytable1
    WHERE keyword LIKE %colname% OR id  LIKE %colname%

    OK, that really doesn't answer my question. Just because they are in different categories is not a valid reason. Why can't they be mixed?
    In any case, you could probably use a UNION query to solve the current problem, but I would have to know more about the complete query. You don't want to use a JOIN.

  • Get Table fields name for an SAP table

    hi,
    i need to pass SAP table name as a parameter to the selection screen of a Report program.
    This prog shud give me the table Fields name along with type and length.
    Is there any standard SAP report program for the same or i have to write my own logic?
    Please advise.
    regards,
    ags.

    Hi,
    For your requirement you have to write own program in dynamic manner by using field symbol concept.
    Use this FM DDIF_FIELDINFO_GET and get the field information of database table.
      call function 'DDIF_FIELDINFO_GET'
        exporting
          tabname        = <master>    u201C Table name
        Tables   
          DFIES_TAB      = <table_field> u201C here you will get field information of table
        exceptions
          not_found      = 1
          internal_error = 2
          others         = 3.
      if sy-subrc <> 0.
        message  text-005 type 'E' .
      endif.
    Loop <table_field> assignigng <field>
    *---here you have to collect the relevant information that you are going to display in your output.
    Endloop.
    Use any one of ALV or OOALV and display your records.
    Regards,
    Peranandam

  • How can i read the field name in the internal table

    Hi friends
    i want to read the internal table filed name.
    my requirement is like this:
    data: begin of t_header occurs 0,
           extno(12),
           priotiy(5),
           ecnumber(10).
          end of t_header.
    loop at t_header.
    if the field name is priority i want to write some other
    logic here.....
    endloop.
    Please tell me how can i do this.

    data: wf_fld_cat type slis_t_fieldcat_alv .
    data: wf_repid like sy-repid .
    data: int_tab_name type slis_tabname .
    move: sy-repid to wf_repid  ,
            'INT_OUTPUT' to int_tab_name .
      call function 'REUSE_ALV_FIELDCATALOG_MERGE'
       exporting
         i_program_name              = wf_repid
         i_internal_tabname          = int_tab_name
      I_STRUCTURE_NAME             =
      I_CLIENT_NEVER_DISPLAY       = 'X'
        i_inclname                   = wf_repid
        i_bypassing_buffer           = 'X'
      I_BUFFER_ACTIVE              =
        changing
          ct_fieldcat                  = wf_fld_cat[]
       exceptions
         inconsistent_interface       = 1
         program_error                = 2
         others                       = 3
      if sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      endif.
    wf_fld_cat[] will hold the itab definition.
    Regards
    Raja

  • How to get field name dynamically of a table

    Hi,
    I have a table which has 5 fields, now i want to know the name of the fields dynamically at run time
    not the values each fields hold.
    I have tried field symbols, get reference but all i got the value of the field not the field name.
    is there any way  i can get the field name.
    regards,
    mayank

    1. If it is a DDIC table, you can use the FM 'DDIF_FIELDINFO_GET'. Search in SDN for details.
    2. If it is an internal table, check this code:
    TYPE-POOLS: abap.
    PARAMETERS p_table TYPE tabname .
    DATA: lcl_table TYPE REF TO cl_abap_tabledescr,
          lcl_struc TYPE REF TO cl_abap_structdescr,
          it_fields TYPE abap_compdescr_tab,
          wa_fields TYPE abap_compdescr.
    DATA: dref TYPE REF TO data.
    FIELD-SYMBOLS: <itab> TYPE ANY.
    CREATE DATA dref TYPE STANDARD TABLE OF (p_table).
    ASSIGN dref->* TO <itab>.
    START-OF-SELECTION.
    * Get the Table details
      lcl_table ?= cl_abap_typedescr=>describe_by_data( <itab> ).
    * Get the table line type i.e., structure details
      lcl_struc ?= lcl_table->get_table_line_type( ).
    * Get the components(fields) of the table line
      it_fields = lcl_struc->components.
      LOOP AT it_fields INTO wa_fields.
        WRITE: / wa_fields-name.
      ENDLOOP.
    BR,
    Suhas

  • Debugging ECC6: how to see the fields name when download internal table?

    When we debug a reprot in ECC6 and save to a local file an internal table, the fields are not appearing only the data,
    Is there a way to download also the table fields name?

    From the new debugger switch to the classic debugger using menu path Debugger->Switch to Classic Debugger. Form the classic debugger you can download internal table data with column name(s).
    Regards,
    Joy.

  • In FTP server same file name with multiple vesions

    Hi All,
    My source system is UNIX. in that FTP server they have multiple files with same name  example " abc.dat"; with different versions example"abc.dat;43" "abc.dat;44", "abc.dat;45". . so how to read latest version file like "abc.dat;45"   from sender communication channel with file adapter.
    suggestions please..Thanks in advance.
    Edited by: venkataraonandigam on Jul 15, 2011 3:12 PM

    Hi VenkatRao,
    Sender file adapter configuration has an option "Processing Sequence". In the that select by"Date" or Name .
    If you used placeholders when specifying the file name, define the processing sequence of the files:
    ○       By Name: Files are processed alphabetically by file name.
    ○       By Date: Files are processed according to their time stamp in the file system, starting with the oldest file.
    Otherwise you have to write shellscrit to move the latest version file to a different folder and pick it up from that folder.
    Or
    write adapter module.

Maybe you are looking for

  • If I buy a new macbook air for travelling, will I be able to transfer the contents of all my mailboxes across?

    I tried to watch an episode of a TV series from my iTunes library and while it looked fine on the Mac screen and sounded fine on the TV screen, on the TV screen the area of the screen where the TV picture should have been was just a chequerboard.  I

  • Multi-mapping 1:n - 1:1

    Hi, We are using multi-mapping in a file-to-file interface. When we have 1:n everything is ok, but when we have 1:1 we have this error: Success The message status set to DLNG. Error Unable to find channel ID Error Delivery of the message to the appli

  • Back up photos, remove from iOS and having them on iCloud

    My iphone and MacBook memory is running out and is mainly occupied by photos. How do I back them up at iCloud and delete them. I want to have access to them  through

  • Query related to smartform.

    Hello sir's, I am doing smartform , in that i have a query that, In one delivery number , if there are 10 items then i want all details of that item numbers and also the sub-totals of that items. Also the final total of all items. Can it is possible

  • Where i can find exemples for PXI-2564 relay module

    hello, I'm beginner in PXI module using. I bought a PXI solution for use it as a custom instrument. My aim is to read RTDs and command some line using relays. So i take the system below: NI PXIe 1071     PXI-8100     PXIe-4357     PXI-2564 I can see