Union query in mysql [closed] - mysql

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I have 2 tables catelog and catelog copy. And, I need to to display both these table fields as one table using mysql.
Can anyone correct this code for joining 2 tables?
$result = mysql_query("SELECT * FROM catelog WHERE title='".$fileid."'union
select status from catelog_copy " );

SELECT statements you'd like to UNION have to return the same number of columns and types of those columns should match.
So
SELECT a, b, c FROM table1 UNION SELECT a, b, c FROM table2
will work, but
SELECT a, b FROM table1 UNION SELECT a, b, c FROM table2
will not.
Names of the fields and the fields themselves might be different though.

Related

select two columns and run update query on them and do this in single query [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
i want to select two columns from database id and password
and want to use those two columns data in update query
example
select id , pass from table
second update query
update table set password2=password_get_from select_query where id=id_get_from_select_query
Try something like.
update table_one as A
inner join table_two AS B on (A.id = B.id)
set A.some_column = B.some_column,
A.another_column = B.another_column
where blah

how to convert colums to rows in sql [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I have a table with the following values
and I need the output values as below.
Please help to arrive the code
It's not pretty, but this would work:
select *
from
(
select nams_contract_number, 1 as Sequence, 'Preqc' as DataType, act_preqc, est_preqc
from table
union all
select nams_contract_number, 2 as Sequence, 'abstractoin' as DataType, act_abstraction, est_abstraction
from table
union all
select nams_contract_number, 3 as Sequence, 'review' as DataType, act_review, est_review
from table
union all
select nams_contract_number, 4 as Sequence, 'postreview' as DataType, act_postreview, est_postreview
from table
) x
order by x.nams_contract_number, x.sequence

How to compare two columns in two different tables in SQL? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have two tables. Table A and Table B. How can I compare a column in A (data type: date)
with a column in B (data type: date) with condition: column in B >= column in A?
There are two things being asked here.
1) Show me those that are greater
2) Tell me the comparison
So, to do both, try this. Part (1) is in the where clause, and part (2) is in the select statement.
select *, datediff(day, b.col, a.col) as ColumnDifference
from TableA a, TableB b
where b.col >= a.col
Documentation for datediff: http://msdn.microsoft.com/en-us/library/ms189794(v=sql.100).aspx

Select SQL Query for two table? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have two tables
Table A : Content Question , its options and correct answer
Table B : This table is for time allow to answer the question in given time.
this table has Question_Id field which either have question id or zero. zero means if for Table A Question Id is not found in Table B then default Time will be Table B's Question_Id=0 > 5 Min
Now I want the data like Result table from query. By using Select Query with Join I am getting question details, which are matched with question Id (1,2,4) means for Question 3,5,6 row not getting that showing in result table.
Please suggest what sql query should write so that I can get result like Result Table's content.
I change your tables to small and simple tables and you can see the result in:
SQL Fiddle
or try this query:
SELECT t1.questionid,
t1.question,
t1.options,
t1.answer,
COALESCE(t2.timingstatement, '5 Min') TimingStatement
FROM tablea t1
LEFT OUTER JOIN tableb t2
ON t1.questionid = t2.questionid;
Try this
SELECT Q.QuestionID,Q.Question,Q.Options,QAnswer,
CASE WHEN Q.QuestionID NOT IN (SELECT QuestionID FROM Table2) THEN '5 Min'
ELSE T.TimingStatement
END [TimingStatement]
FROM Table1 Q
JOIN Table2 T ON Q.QuestionID = T.QuestionID

in Table A has 10 rows and table B has 10 rows. The product of Table A and Table B would have 100 rows. ? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
In mySQL Table A has 10 rows and table B has 10 rows. The product of Table A and Table B would have 100 rows?
I am stuck.
If table1 has N rows and table2 has M rows, and you do:
SELECT * FROM table1 A, table2 B
you get N X M rows.
Check if you like Generating a Cartesian Product.
What exactly is the product of two tables? If you join them loosely and select one column from each theb yes. But it makes no sense to do it.
You are probably not joining them properly. If you could post your code it would help.