Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

MySQL - Alias Question

Guest
Nov 10, 2009 Nov 10, 2009

Hi Chaps, 

Have a quick one for you...

In a SQL Query, I know you can create an alias for column name, eg.

...tbl_jobxml.job1 as job2


but can you create an alias for the value within that column, eg.

...tbl_jobxml.job1='y' as job2='Complete'


Sorry if this is dumb question, but better to ask that claim ignorance!

????

TOPICS
Server side applications
518
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Participant , Nov 10, 2009 Nov 10, 2009

I dont think that will work, as you are telling the query to find "y" in the field.

If the field had "y" input as a value it will work fine.


But I dont think an alias will work on value.

Translate
Participant ,
Nov 10, 2009 Nov 10, 2009

I dont think that will work, as you are telling the query to find "y" in the field.

If the field had "y" input as a value it will work fine.


But I dont think an alias will work on value.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 10, 2009 Nov 10, 2009

littlemookie wrote:

but can you create an alias for the value within that column, eg.

...tbl_jobxml.job1='y' as job2='Complete'

In a word, No.

It might be better if you said what you're trying to achieve.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 10, 2009 Nov 10, 2009

Sounds like you are looking for a case statement. I'm not sure if MySQL support those in select statements, or only in sprocs. Many DBMS's do support this.

OK, found this on the web:

SELECT (CASE field1 WHEN 'Yes' THEN 1 WHEN 'No' THEN 0 ELSE 0 END) FROM mytable;

Message was edited by: bregent

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Nov 12, 2009 Nov 12, 2009

Hi Guys,

sorry to the delay in responding, basically this is what I want to do:

I want to show all results when:

- tableA

projectstatus='complete'

- tableB

projectstatus='complete'

- tableC

jobstatus='y'

I'm familiar with UNIONs and INNER JOINs, it's just not sure how to go about getting all the results form the 3 tables, when the values are different.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 12, 2009 Nov 12, 2009
LATEST

You would just add those conditions to the where clause:

where tableA.projectstatus='complete' and tableB.projectstatus='complete' and tableC.jobstatus='y'

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines