NCS_One Posted October 24, 2009 at 01:23 PM Report Share #293157 Posted October 24, 2009 at 01:23 PM Boas. É possivel no mesmo "select" fazer um query a uma tabela e com um campo que é retornado fazer um query a outra tabela ? Ex: Table1 tem : user_id e user_name. Table2 tem : table_id e user_id. Fazer um query à Table2 para retornar o user_id e com esse user_id ir à Table1 buscar o user_name de quem tem o user_id igual ao que foi retornado pela Table2. Agradeço toda a ajuda. Se a vida te voltar as costas aproveita e apalpa-lhe o cu. Link to comment Share on other sites More sharing options...
NCS_One Posted October 24, 2009 at 01:38 PM Author Report Share #293160 Posted October 24, 2009 at 01:38 PM Seria qualquer coisa como isto ? SELECT Table2.user_id, Table1.user_name FROM Table2 WHERE Table2.table_id = 1 INNER JOIN Table1 ON (Table1.user_id = Table2.user_id); ou : SELECT Table2.user_id, Table1.user_name FROM Table2, Table1 WHERE Table2.table_id = 1 AND Table1.user_id = Table2.user_id; Se a vida te voltar as costas aproveita e apalpa-lhe o cu. Link to comment Share on other sites More sharing options...
Betovsky Posted October 24, 2009 at 07:23 PM Report Share #293206 Posted October 24, 2009 at 07:23 PM O que queres é tipo a primeira hipotese mas tens o WHERE no sitio incorrecto. O WHERE vem depois dos JOINs. SELECT Table2.user_id , Table1.user_name FROM Table2 INNER JOIN Table1 ON (Table1.user_id = Table2.user_id) WHERE Table2.table_id = 1; "Give a man a fish and he will eat for a day; Teach a man to fish and he will eat for a lifetime. The moral? READ THE MANUAL !" Sign on a computer system consultant's desk Link to comment Share on other sites More sharing options...
NCS_One Posted October 26, 2009 at 06:54 PM Author Report Share #293449 Posted October 26, 2009 at 06:54 PM Obrigado. Mais uma coisa, se for uma lista limitada como o faço ? SELECT Table2.table_id, Table2.user_id FROM Table2 ORDER BY Table2.table_id DESC LIMIT 10 OFFSET 0 Assim vou buscar a lista, mas como faço para ir buscar o Table1.user_name ? Se a vida te voltar as costas aproveita e apalpa-lhe o cu. Link to comment Share on other sites More sharing options...
NCS_One Posted October 27, 2009 at 01:39 PM Author Report Share #293559 Posted October 27, 2009 at 01:39 PM É possível fazer um insert e um update na mesma query ? Se a vida te voltar as costas aproveita e apalpa-lhe o cu. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now