• Lidou123 (4/17/2015)


    Hi experts,

    I am working with access 2013 and I want to add an extra row in my select query.

    With sql server I used an union like this:

    select ColumnA, ColumnB from My Table

    union 1 as ColumnA , 1 as ColumnB

    But I have an error when I tried to do that with Access database.

    Do U have a solution ??

    Thank U

    UNION is used for joining multiple queries into a single result set. Each query must be a complete query. Your second part is missing the select keyword.

    select ColumnA, ColumnB from My Table

    union ALL

    Select 1 as ColumnA , 1 as ColumnB

    --EDIT--

    Notice I included the keyword ALL in the UNION? If you don't do that the query will only return unique rows. Since you are trying to add another row it will be more efficient to use UNION ALL so the query engine doesn't bother looking to see if the rows of unique.

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/