How to write a search query in mysql which matches columns from different tables and returns another column from the first table?

时间:2017-12-18 04:52:46

标签: mysql

Table_1

Name    Age    City           Mobile
John S  40    New York        444444
Roy M   24    London          999999
Smith   30    Venice          444555

Table_2
Name      Age   Gender
John S    40      M
Sussane   28      F

What will be the query to match columns from Table_1 Name, Age and Table_2 Name,Age and return Mobile from Table_1.

2 个答案:

答案 0 :(得分:0)

Try this,

select t1.mobile from table_1 t1, table_2 t2 where t1.name = t2.name and t1.age = t2.age

答案 1 :(得分:0)

What do you mean by match columns in

What will be the query to match columns from Table_1 Name, Age and Table_2 Name,Age and return Mobile from Table_1.

Your use case is not clear. I am assuming you want to exactly match Name and Age from each row of val df = spark .readStream .format("kafka") .option("kafka.bootstrap.servers", "localhost:9092") .option("subscribe", "myTopic2") .load() val query = df .selectExpr("CAST(key AS STRING)", "CAST(value AS STRING)") .writeStream .format("parquet") .option("checkpointLocation", "/path/to/hdfs/checkpoint") .option("path", "/path/to/hdfs/data") .start() . But what if there are multiple John S? Hence you should use a database key to identify the tuple(e.g. table_2).

You can use following query for the time-being:

user_id int auto_increment