How to select Specific Columns from same row in SQL Server

Viewed 240

Here is my table funcionario:

ID_funcionario  nome    numero  sexo    morada    email     data_nasc
-----------------------------------------------------------------------
1              marcio   1234    male    jardim    marcio    11/23/2017
2              joel     3333    male   bemfica     ragy     11/25/2017 

I want to select specifically only the nome "marcio" and number 1234.

For example, it should appear like this:

nome    numero  
----------------
marcio  1234

This is what I tried:

select * 
from funcionario 
where nome = 'marcio' and numero = '1234';

but that just shows me the whole row like this:

ID_funcionario  nome    numero  sexo    morada    email     data_nasc
----------------------------------------------------------------------
1              marcio   1234    male    jardim    marcio    11/23/2017
4 Answers

When you use select * ..., all the columns of the table are returned.

If you want to get only some columns, then you must be more specific, like this:

select nome, numero 
from funcionario 
where nome = 'marcio' and numero = '1234';

You are selecting every column by this: SELECT * FROM ...

try to select the columns you need by:

select nome, numero from funcionario where nome ='marcio'and numero='1234';

In addition to the answers above, you could also write it this way:

select nome, numero 
from funcionario 
where nome = 'marcio' 

It will return your desired result as well.

SELECT * FROM [TABLENAME] WHERE Col1 = ''

or

SELECT T_Col1, T_Col2 FROM [TABLENAME] WHERE T_Col1 = ''

Related