我需要加入4个表并执行select [英] I need to join 4 table and perform select
问题描述
嗨!
我有4张桌子(table1,table2,table3,table 4)
我需要从所有四个表中选择*并将它们排序
所有表都有字段名为id,所以我想'我应该加入所有表的字段
let'' s表示table1有5条记录,table2有3
当我选择时我希望table2的id从6开始到8
所以...
当我选择id会从1-8
并且有一种方式我可以得到一个来自table2的id(或者我必须从所有表中减去第一个表(table1)中的id ....)
如何从4个表中选择*?他们都有字段名称ID,我想使用该字段连接表格
i使用php,所以我有一个名为$ t的变量,我想对此使用类似的查询
$ t =" something";
SELECT * FROM table1 WHERE field1 LIKE''%$ t%''OR field 2 LIKE''%$ t%''
当我使用四个查询但它希望能够加入查询并得到一个结果时它可以工作......如果可能的话,我希望id字段不具有重复值(如上所述)我希望他们从1-number_of_id_from_table1开始,然后只需将该数字添加到table2中的id,依此类推......)
如果有办法获取表名,或id(iefrom table2)....我不知道如何描述它...但如果我的table1有3条记录而table2有2条记录,那么table2中的第一个id将有id = 5
thx
t我想对此使用类似的查询
SELECT * FROM table1 WHERE field1 LIKE''%
t%''OR field 2 LIKE''%
Hi!
I have 4 tables (table1, table2, table3, table 4)
I need to do select * from all four table and get them sorted
all the tables have field named id, so I figured that''s the field I should join all the tables with
let''s say table1 has 5 records in it, and table2 has 3
when I do select I want that id from table2 starts from 6 and goes to 8
so...
when i do select the id would go from 1-8
and is there a way that i could get an id from table2(or i have to subtract id from first table(table1) from all tables....)
how do I select * from 4 tables? they all have field name id and I want to join tables using that field
i use php, so I have a variable named $t and I want to use similar query to this
$t="something";
SELECT * FROM table1 WHERE field1 LIKE ''%$t%'' OR field 2 LIKE ''%$t%''
it works when I use four queries but I want to be able to join queries and get one result... and if possible I want the id field not to have duplicate values (as described, i want them to go from 1-number_of_id_from_table1 and then just add that number to id from table2 and so on...)
and if there''s a way to get the table name, or id(i.e.from table2).... I don''t know how to descibe it... but if my table1 has 3 records and table2 has 2 record, then the first id from table2 would have id=5
thx
t and I want to use similar query to this
t="something";
SELECT * FROM table1 WHERE field1 LIKE ''%
t%'' OR field 2 LIKE ''%
这篇关于我需要加入4个表并执行select的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!