0

Imagine I have a table like this one:

CREATE TABLE marcas
(
  id_marca integer,
  marca character varying
));

I would like to make a query but get the value in every field empty.

I know that could solve it like this:

SELECT '' as id, '' as marca FROM marcas

The problem is that i have plenty of tables and some of them have more than 100 fields... I need a SQL statement that could get all the row fields of a table but empty and in an easy way...

2
  • what sql implementation are you using? MSSQL, Postgres, etc. Commented May 19, 2014 at 14:17
  • 1
    What is that you really need? The tables structure? Or something else? Commented May 19, 2014 at 14:17

3 Answers 3

4

Here is one method to get NULL in every column. It uses left outer join with a failing condition:

select t.*
from (select 1 as val
     ) v left outer join
     table t
     on 1 = 0;

EDIT:

If you want to do this in Access, that is a challenge. The expression select 1 as val doesn't work. The following should:

select t.*
from (select max(1) as val
      from table as t 
     ) as v left outer join
     table as t
     on val = 0;

This should also work in Postgres, but it has unnecessary overhead.

Sign up to request clarification or add additional context in comments.

3 Comments

+1 I think this is pretty much as close as you can get.
This query worked perfectly on PostgreSQL but gets an error when trying to execute it in Microsoft Access, it says that 1 = 0 expression is not admitted.
Thanks Gordon for your answer. I opened a new thread here: stackoverflow.com/questions/23760573/ms-access-query looking for a specific solution on this question in ms-access. Your solution for access in my case is not working...although it works again in PostgreSQL.
0

If you use

SELECT * FROM MARCAS

you will get a result set of

===================

ID_MARCA | MARCA

===================

This will return zero results but it will show all the columns in the table queried. I can't fully understand what you are trying to achieve.

Comments

0

if you just want the column list and no rows returned then

SELECT TOP 0 * FROM marcas

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.